加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

将www重写为非www和index.php CI

发布时间:2020-12-13 17:45:50 所属栏目:PHP教程 来源:网络整理
导读:我使用CodeIgnter,结果我的所有链接都像base.com/index.php/home/index或www.base.com/index.php/home/index. 如果可能的话,我想将它们仅显示为base.com/home/index.我试过通过互联网查看,从两者中获取重写为htacces: RewriteEngine onRewriteCond %{REQUES
我使用CodeIgnter,结果我的所有链接都像base.com/index.php/home/index或www.base.com/index.php/home/index.
如果可能的话,我想将它们仅显示为base.com/home/index.我试过通过互联网查看,从两者中获取重写为htacces:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$index.php/$0 [PT,L]  
RewriteCond %{HTTP_HOST} ^domain.com$[OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^/?$"http://domain.com/" [R=301,L]

RewriteEngine on
RewriteCond %{HTTP_HOST} !^domain.com$[NC]
RewriteRule ^(.*)$http://domain.com/$1 [R=301,L]

把它们分开,他们工作.但是他们不做我需要他们做的事.
有人知道解决方案吗?谢谢.

解决方法

对于CI,您需要类似于您的第一组规则,但没有重定向.但重定向需要在路由发生之前发生,因此请尝试:

RewriteEngine On

# redirect www to non-www
RewriteCond %{HTTP_HOST} ^www.base.com$[NC]
RewriteRule ^(.*)$http://base.com/$1 [L,R=301]

# redirect direct requests to /index.php to remove it
RewriteCond %{THE_REQUEST}  /index.php/?([^? ]*)
RewriteRule ^ http://base.com/%1 [L,R=301]

# internally route to /index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$/index.php/$1 [PT,L]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读