Oct
01
2023
Apache和Nginx下去掉index.php的URLWRITE(url重写)的方法
作者:
绝缘体.. 发布:
2023-10-01 14:37 分类:
未分类 阅读:
抢沙发
(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;
}
}
微信扫一扫,打赏作者吧~