문제

I have two websites that is actually the same where example.com shares all files from examples.com. So whatever changes made in exampples.com, example.com automatically gets updated. That means they have the same .htaccess file. The problem is, I want to both sites redirects to non www to a www url. I got this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
도움이 되었습니까?

해결책

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

다른 팁

This should do it:

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

Basically you're adding an OR condition to say if either example.com or examples.com doesn't begin with www. then add it to the respective domain name.

replace example.com with %{HTTP_HOST} to make your rules host independent

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top