URL Rewrite

OK, so I want to replace example.com/x with www.example.com/X. When I follow the in-line tutorials I get: www.example.comX
Here is the .htaccess snipet

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

Put a / before the $1 in the RewriteRule.

I assume the difference in capitalization is just a typo, because you’re not doing anything there regarding that…

Since you’re doing this inside a .htaccess file (as opposed to the main server httpd.conf), the rules are slightly different. mod_rewrite will remove everything up to the current directory level and then apply the match. So your (.*) pattern is matching ‘X’ instead of ‘/X’.

There’s a confusingly-worded explanation of this in the mod_rewrite documentation here:

So, two possible fixes:

  1. Put this in the main httpd.conf, which is where it should probably be if you’re doing redirects at the server root.

  2. Change your RewriteRule to:
    RewriteRule (.*) http://www.example.com/$1

As usual, you guys rock