目前我有htaccess從URL中刪除index.php,其工作正常。但現在我想強制網址以www
開頭。htaccess強制www和刪除index.php
我當前的代碼:
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 htaccess刪除index.php和www]的可能重複(http://stackoverflow.com/questions/12030990/codeigniter-htaccess-to-remove-index-php-and-www) – Oberst 2014-08-29 17:28:11
這個問題是不一樣的,這裏我要求不要刪除www,而是強制要求www。請正確閱讀 – 2014-08-29 17:32:28
否...不是完全重複,但答案仍然存在。 'RewriteCond%{HTTP_HOST}^domain.com [NC] RewriteRule ^(。*)$ http://www.domain.com/$1 [L,R = 301]' – Oberst 2014-08-29 17:36:23