Archive for July 28th, 2010

Fix an extra slash beeing added during domain redirect to www with mod_rewrite

Wednesday, July 28th, 2010

I have recently added a redirect to www forwarding for a domain using mod_rewrite capabilities.
The exact mod rewrite rules I in my <VirtualHost> used was:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.pc-freak.net
RewriteRule (.*) https://www.pc-freak.net/$1 [R=301,L]

Nevertheless the redirect was okay I have noticed that everytime the redirect has been in move from domain.com to www.domain.com an extra slash has been added included right after the domain, an example of the unwanted behaviour I have encountered is illustrated in the picture below:

Double Splash domain issue in mod_rewrite redirect to www

A help from a good guy in irc.freenode.net #httpd under the alias jink told me that me that in order to solve the extra slash added to the url I need to modify the rewrite rules to look like the one below:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.pc-freak.net
RewriteRule (.*) https://www.pc-freak.net$1 [R=301,L]

Thanks God This solved the issues.