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"

link|improve this question
feedback

1 Answer

up vote 2 down vote accepted

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

 RewriteRule (.*)  posts/...

Use this:

 RewriteRule (.*)   /posts/...
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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