Apache和Nginx下去掉index.php的URLWRITE(url重写)的方法

 
更多

(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;
    }
}
打赏

本文固定链接: https://www.cxy163.net/archives/3061 | 绝缘体

该日志由 绝缘体.. 于 2023年10月01日 发表在 未分类 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: Apache和Nginx下去掉index.php的URLWRITE(url重写)的方法 | 绝缘体
关键字: , , , ,

Apache和Nginx下去掉index.php的URLWRITE(url重写)的方法:等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter