本來是簡單的官網,由于原本路徑太長宝磨,推廣說不利于優(yōu)化弧关,需要做【偽靜態(tài)】,
第一步去掉xx.com/index.php的index.php后綴
- 如果是LAMP環(huán)境(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環(huán)境的話是修改對應的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;
}
}
這一步本來正常的腌紧,但是我配置后緩存嚴重茸习,懷疑人生了,建議大家清下緩存或者更換瀏覽器確認壁肋。
后續(xù)鏈接縮減長度号胚,
參考原路徑改為 => 偽靜態(tài)路徑
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',[]);