【发布时间】:2014-08-29 17:22:07
【问题描述】:
目前我有 htaccess,它从 URL 中删除 index.php,它工作正常。但现在我想强制 url 以 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]
我尝试了以下代码,但它不起作用:
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
【问题讨论】:
-
这个问题不一样,这里我要求不要删除www,而是强制www。请正确阅读
-
不...不是完全重复,但答案仍然存在。
RewriteCond %{HTTP_HOST} ^domain.com [NC] RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
标签: php apache .htaccess codeigniter mod-rewrite