Apache和Nginx下去掉index.php的URLWRITE(url重写)的方法
admin 阅读:173 2024-02-29
(1)apache使用.htaccess重写去掉index.php方法:
//保护系统路径的写法,在RewriteCond规则中写入开放的路径
RewriteEngine On RewriteCond $1 !^(index.php|sitemap.xml|robots .txt|assets) RewriteRule ^(.*)$ /index.php/$1
//不保护系统路径的写法
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L](2)Nginx重写去掉index.php的方法:
在 location 路由规则里(当然可以根据具体的情况放在需要的地方)面加入类似如下两行代码:
if (!-e $request_filename) {
rewrite ^/index.php(.*)$ /index.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}例如:
location / {
......
#rewrite 去掉index.php规则如下:
if (!-e $request_filename) {
rewrite ^/index.php(.*)$ /index.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}声明
1、部分文章来源于网络,仅作为参考。 2、如果网站中图片和文字侵犯了您的版权,请联系1943759704@qq.com处理!



