htaccess强制www并删除index.php [英] htaccess force www and remove index.php
本文介绍了htaccess强制www并删除index.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前,我有htaccess可以从URL中删除index.php,它的工作正常.但是现在我要强制url以www
开头.
Currently I have htaccess which removes index.php from URL, its working fine. But now I want to force url to start with www
.
我当前的代码:
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
我尝试了以下代码,但没有用:
I tried following code, but its not working:
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
#RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI}/index.php?/$1 [R=301,L]
但是它不起作用,我正在使用codeigniter
But its not working, I am using codeigniter
推荐答案
在重写规则之前更改规则的顺序并保留重定向:
Change order of your rule and keep redirects before rewrite rules:
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
这篇关于htaccess强制www并删除index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文