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]

With just the first RewriteRule line, the server correctly redirects. When the other three lines are included and we navigate to "http://localhost/posts/1/first-post-title", Safari is giving an error of:

Too many redirects occurred trying to open “http://localhost/posts/1/first-post-title”. This might occur if you open a page that is redirected to open another page which then is redirected to open the original page.

  • External redirects should nearly always be root-relative or absolute or specify an appropriate RewriteBase. (This would be a second problem after the redirect loop was resolved.)
    – MrWhite
    Oct 31 '15 at 1:47

Your second line (first RewriteCond rule) is causing a perpetual match. The URL you redirect people to is matching and being redirected again. Drop that rule entirely and you should be good to go.

  • It's not simply the first RewriteCond that "is causing a perpetual match". The whole second rule (2 conditions and a rewrite) would seem to be flawed.
    – MrWhite
    Oct 31 '15 at 1:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy