问题
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