Apache 使htaccess接受domain.com和www.domain.com

Apache 使htaccess接受domain.com和www.domain.com,apache,.htaccess,mod-rewrite,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 ^$ w

如何修改此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没有太多的了解,只需拿出第一条301规则,删除
www

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]

谢谢您的回复,但它仍在将url从www.domain.com更改为domain.com。您能在新浏览器中尝试此操作以避免缓存问题吗?很高兴知道它成功了。是301状态由浏览器主动缓存。