.htaccess重写不带www的url
根据以下规则,当我键入url.htaccess重写不带www的url,.htaccess,url-rewriting,.htaccess,Url Rewriting,根据以下规则,当我键入urlwww.mywebsite.com时,我将被重定向到mywebsite.com/www。为什么? 我需要重定向到mywebsite.com RewriteEngine on RewriteCond %{HTTP_HOST} ^www.mywebsite.com [NC] RewriteRule ^(.*)$ http://mywebsite.com/$1 [L,R=301,NE] 示例: www.mywebsite.com重定向到=>mywebsite.com/w
www.mywebsite.com
时,我将被重定向到mywebsite.com/www
。为什么?
我需要重定向到mywebsite.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.mywebsite.com [NC]
RewriteRule ^(.*)$ http://mywebsite.com/$1 [L,R=301,NE]
示例:
www.mywebsite.com
重定向到=>mywebsite.com/www
|需要=>mywebsite.com
www.mywebsite.com/folder
重定向到=>mywebsite.com/www/folder
|需要=>mywebsite.com/folder
谢谢尝试此解决方法
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com [NC]
RewriteCond %{THE_REQUEST} \s(\/\S*)\s
RewriteRule ^ http://mywebsite.com/%1 [L,R=301]
是的,对不起,我的错,这是我知道的真实代码。我在共享服务器上,如何激活重写日志?您必须请求主机提供商启用它。在Apache2.4上,它是一个日志选项。@anubhava它实际上是我的全部。htaccess@anubhavawww.mywebsite.com出现301错误,然后我被重定向到mywebsite.com/www。我不明白为什么需要“www”子域将其放在url后面。@anubhava没有htaccess,我可以浏览www,也可以浏览www。我不想做的似乎什么也做不了:/。我可以使用www和不使用www访问该网站。{the_REQUEST}行的作用是什么?@Lunic
GET/index.html HTTP/1.1
。此条件采用/index.html
。如果不支持\s
,请尝试RewriteCond%{THE_REQUEST}\(\/[^\]*)