mod_rewrite: ohne www. nach www. weiterleiten

Kleines mod_rewrite reciept um URIs ohne “www.” nach URIs mit “www.” weiterzuleiten. Verbesserungen willkommen…

RewriteEngine on
RewriteCond %{HTTPS} =on
RewriteRule ^(.+)$ - [env=ps:https]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.+)$ - [env=ps:http]

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

Inspiriert von hier.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.