Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a VPS on which I'm trying to setup multiple websites. For one of them, with the current set of rules (below), accessing


sends me to

hxxp:// [note the two //]

My httpd.conf looks like:

NameVirtualHost *:80

[other VirtualHosts]

<VirtualHost *:80>
DocumentRoot /var/www/html/

RewriteEngine On
RewriteCond %{HTTP_HOST} ^
RewriteRule (.*)$1 [R=301,L]

<directory /var/www/html/>

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^([0-9]+)(.*)/?$ /showitem.php?j=$1 [NC]

share|improve this question

4 Answers 4

up vote 1 down vote accepted

Try this one:

RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*)$1 [R=301,L]
share|improve this answer
Thanks casper!! – siliconpi Jan 20 '12 at 14:07
+1 The Request URI includes the leading slash. – Chris S Jan 20 '12 at 14:26
That would be a reason to use RewriteRule /(.*) and match it in the target, not the opposite. – adaptr Jan 20 '12 at 17:50

The problem is that .* includes the slash that is already in the URL. You then send a redirect to$1 which includes another slash.

One of the following will fix your problem:

RewriteRule (.*)$1 [R=301,L]


RewriteRule /(.*)$1 [R=301,L]

This will not happen inside a <Directory > block or in a .htaccess file because in both those cases there is no leading slash on the URI.

share|improve this answer

You can easily get rid of that double / by letting the regex part of the directive "eat" it:

RewriteRule ^/(.*)$$1 [R=301,L]
share|improve this answer

I've never heard of the hxxp protocol.

Your virtualhost answers to both and requests.

The fix is simple: Add a separate vhost for and remove the ServerAlias from

Then Redirect permanent /

Note the prevalence of the slash on both source and target - that is the mistake you made.

I'm not going to show you how to fix the rewiterule, since you shouldn't be using it.

share|improve this answer
Umm - that's because I'm a new user and making more than two links like isnt allowed – siliconpi Jan 20 '12 at 13:45
I don't know what that means. Don't use rewrites when anything else will do the job. – adaptr Jan 20 '12 at 17:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.