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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The .htaccess we have in our document_root directory is as follows:

RewriteEngine on

RewriteRule ^posts/1/first-post-title$ /posts/1.html [L]
RewriteCond %{REQUEST_URI} ^/posts/1
RewriteCond %{REQUEST_URI} !/^posts/1/first-post-title$
RewriteRule (.*) posts/1/first-post-title [R=301,L]

The configuration is designed so that the following URLs will all point to "http://localhost/posts/1/first-post-title":

  • "http://localhost/posts/1"
  • "http://localhost/posts/1/wrong-title"
  • "http://localhost/posts/1/first-post-title"

The second line works fine and "http://localhost/posts/1/first-post-title" looks at /posts/1.html

Unfortunately, when either of the other to URLs are used, the user gets redirected to "http://localhost/path/to/document_root/posts/1/first-post-title"

share|improve this question
up vote 2 down vote accepted

Change your rewrite to be absolute, e.g. rather than this:

 RewriteRule (.*)  posts/...

Use this:

 RewriteRule (.*)   /posts/...
share|improve this answer

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.