Redirect to site if WWW part is missing

有些话、适合烂在心里 提交于 2019-12-24 01:25:51

问题


After viewing answer of almost a same question on SO i added this line in .htaccess

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

But it did not worked for these 2 cases

example.com
example.com/
example.com/index.php

In other cases it successful redirected to the www.example.com/...
What is wrong in my .htaccess ?

Additional Info
For some kind of unknown reason [to me at least] i can not enable ERROR page for PHP, but works fine for HTML only.


回答1:


If I understand you correctly this is a dns issue. Try adding a cname record:

CNAME yourdomain.com www.yourdomain.com



来源:https://stackoverflow.com/questions/6785310/redirect-to-site-if-www-part-is-missing

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