首页 > 服务器    日期:2020-02-20 / 来自互联网 / 浏览

(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 路由规则里(当然可以根据具体的情况放在需要的地方)面加入类似如下两行代码:

rewrite ^/$ /index.php last;
rewrite ^/(?!index.php|robots.txt|static)(.*)$ /index.php/$1 last;
    
例如:

location / {
    ......
    #rewrite 去掉index.php规则如下:
    rewrite ^/$ /index.php last;
    rewrite ^/(?!index.php|robots.txt|static)(.*)$ /index.php/$1 last;
}

觉得上面的内容有用吗?快来点个赞吧!

点赞() 我要打赏

温馨提示 : 本站内容来自会员投稿以及互联网,所有源码及教程均为作者总结编辑,请大家在使用过程中提前做好备份,以免发生无法预知的错误,源码类教程请勿直接用于生产环境!

 可能感兴趣的文章