non-www to www htaccess redirect

断了今生、忘了曾经 提交于 2019-12-11 03:57:37

问题


I have a .net url which works perfectly with the www in front of it but when the url is just http://example.net its bringing up an under construction page.

I have tried all sorts of .htaccess files but nothing is working! Help!


回答1:


Im not a web developer nor a sys admin, but i think the default domain has to point to the same directory the subdomain www points to.

Imo the default is, that example.com leads to your content and www.example.com forwards to example.com. That's how it's done (according to http://no-www.org/):

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



回答2:


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


来源:https://stackoverflow.com/questions/3707319/non-www-to-www-htaccess-redirect

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!