Codeigniter htaccess to remove index.php and www


Codeigniter htaccess to remove index.php and www

我正在尝试让我的htaccess重写规则从URL中删除index.php,并将www.请求重定向到非www版本。

这是我的htaccess,它可以很好地删除索引.php:

RewriteEngine on
RewriteCond $1 !^(index'.php|resources|robots'.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

我遇到了另一个关于如何删除www部分的问题:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www'.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

但我似乎无法让他们一起玩得很好! 任何意见/建议非常感谢!

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www'.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond $1 !^(index'.php|resources|robots'.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

RewriteEngine On"开始"重写。 RewriteCondRewriteRule成对工作。在这里,我们首先将用户发送到非 www 版本,并清理 URL。

首先需要确保首先出现"非 www"重写规则,然后是将所有请求重定向到 CodeIgniter 引导程序文件的规则。请注意,以下代码将仅接受 HTTP 重写。如果你还需要HTTPS,它需要一些修改。

RewriteEngine on
# Sending all www requests to the non-www version.
RewriteCond %{HTTP_HOST} ^www.domain.com [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
# Now the CodeIgniter part
RewriteCond $1 !^(index'.php|resources|robots'.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]