让htaccess接受domain.com和www.domain.com

时间:2014-02-03 14:27:34

标签: apache .htaccess mod-rewrite

如何修改此htaccess以便允许www.domain.com和domain.com。现在,当我给www.domain.com时,它会将其更改为domain.com

Options -Indexes
Options +FollowSymLinks

RewriteEngine on

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

RewriteRule ^$ website/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/website%{REQUEST_URI} -f
RewriteRule .* website/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* website/index.php?q=$0 [QSA]

抱歉,对htaccess

了解不多

1 个答案:

答案 0 :(得分:1)

只需取出剥离www的前301条规则:

Options -Indexes
Options +FollowSymLinks

RewriteEngine on

RewriteRule ^$ website/index.php [L]

RewriteCond %{DOCUMENT_ROOT}/website%{REQUEST_URI} -f
RewriteRule .* website/$0 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* website/index.php?q=$0 [L,QSA]
相关问题