Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.