How can I redirect all non-www links to www links? I have found solutions on the internet, but they only redirect the domain name.
How do I make this general:
http://example.com/testing
should redirect to http://www.example.com/testing
?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
try something like this
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
回答2:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.yourdomain.com/$1
If you want something generic that works for any domain, you can try something like:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(.+)$
RewriteRule ^(.*)$ http://www.%1/$1