thinkphp5.0伪静态修改
2020-06-09 本文已影响0人
sir_da5c
本来是简单的官网,由于原本路径太长,推广说不利于优化,需要做【伪静态】,
第一步去掉xx.com/index.php的index.php后缀
- 如果是LAMP环境(apache),
修改 .htaccess适配tp5先把index.php去掉,配置参考:
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L]
</IfModule>
- 如果是LNMP环境的话是修改对应的nginx.conf,(nginx1.15/conf/vhosts/xxx.xxx.com_80.conf)配置参考:
location / {
###省略....
###省略....
index index.php index.html error/index.html;
error_page 400 /error/400.html;
include /WWW/thinkphp5/public/nginx.htaccess;
}
nginx.htaccess文件参考
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
}
或者直接把nginx.htaccess的内容放到nginx.conf
location / {
###省略....
###省略....
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
}
这一步本来正常的,但是我配置后缓存严重,怀疑人生了,建议大家清下缓存或者更换浏览器确认。
后续链接缩减长度,
参考原路径改为 => 伪静态路径
index/index/index/ =>index
index/index/news/ =>news
index/index/about/ =>about
index/news/details?id=1 =>details/1
这种方法,想缩减一下,在tp5.0的路由route.php里添加配置,参考
Route::get('index', 'index/index/about');
Route::get('about', 'index/index/about');
Route::get('news', 'index/index/news');
Route::get('details/:id', 'index/news/details',[]);