Apache .htaccess - Redirect www to non-www or vice versa

Submitted by Gast (nicht überprüft) on Fr, 11/03/2017 - 18:17

Redirect www to non www properly (wildcard / any hostname)

RewriteEngine On<br />
RewriteBase /

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

 

Redirect www.example.com to example.com (with hostname):

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

 

Redirect example.com to www.example.com (with hostname):

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

 

 

Neuen Kommentar schreiben

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.