【问题标题】:rewriting www to non-www and index.php CI将 www 重写为非 www 和 index.php CI
【发布时间】:2013-10-08 04:42:19
【问题描述】:

我正在使用 CodeIgnter,因此我的所有链接都类似于 base.com/index.php/home/indexwww.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]

将它们分开放置,它们可以工作。但是它们一起不会做我需要他们做的事情。 有人知道解决方案吗?谢谢。

【问题讨论】:

    标签: php .htaccess codeigniter


    【解决方案1】:

    对于 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]  
    

    【讨论】:

      猜你喜欢
      • 2017-12-04
      • 2014-12-16
      • 2013-10-23
      • 1970-01-01
      • 1970-01-01
      • 2015-01-10
      • 1970-01-01
      • 2017-01-02
      • 1970-01-01
      相关资源
      最近更新 更多