When trying to redirect an URL in apache from:
www.example.com
to
example.com
it redirects to
example.com//
This is a one page webserver, Fixed IP goes directly to the page.
Editing directly on httpd.conf
Any idea of why is this happening?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com [nocase]
RewriteRule ^(.*) http://example.com/$1 [last,redirect=301]
Where is that rule configured?
Seems like it's probably in the server or virtualhost configuration, where it would have a leading slash in the match string, which is being captured and replaced into the redirect string.
Try this:
It doesn't seem like you need to be using mod_rewrite for this, if that's all the complexity you need. If your rules don't need to be any more complex than this, use
Redirect
instead:How about change the line
RewriteRule
to:Is this in a
.htaccess
file or a<Directory />
block? My guess is that it is not.Inside those two areas, the URI path is matched to a full filesystem path and the the part that matches the directory, including the slash, is removed.
Outside one of these areas, the URI path starts with a slash. Hence, your redirect puts an extra slash in.
You can change the rewrite rule to either:
Or