Skip to content
PHP Logo

What potential pitfalls can occur when using mod_rewrite to remove "www" from URLs?

Potential pitfalls when using mod_rewrite to remove "www" from URLs include creating an infinite loop if not properly configured, causing the website to become inaccessible. To solve this issue, you can add a condition to the rewrite rule to check if the hostname already contains "www" before redirecting.

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