htaccess - 添加www&删除index.php

时间:2014-03-01 14:29:44

标签: php apache .htaccess mod-rewrite redirect

我现在的htaccess是:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?load=$1 [PT,L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

当我去abc.com时,它会正确地重定向到www.abc.com,这很好。

但是,如果我去abc.com/about - 它会重定向到abc.com/index.php?load=about,我希望它重定向到www.abc.com/about。

请帮忙。

2 个答案:

答案 0 :(得分:0)

更改规则的顺序:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?load=$1 [PT,L,QSA]

答案 1 :(得分:0)

强迫WWW:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com[nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc]

删除index.php:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]