Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

R flag breaking redirect in .htaccess

10:41 pm on Aug 12, 2014 (gmt 0)

New User

joined:Aug 12, 2014
posts: 1
votes: 0

I've looked through the postings and I'm sure my problem is simple but cannot find an answer.

I set up .htaccess with the following rewrite rule:

RewriteRule ^mukilteo.*$ roofers-mukilteo.php

That works fine and redirects with no problem. Then I add a redirect flag:

RewriteRule ^mukilteo.*$ roofers-mukilteo.php [R]

This breaks the redirect and returns a url that includes the HTTP_HOST followed by the apache path to the file

Can anyone help?
11:08 pm on Aug 12, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:July 3, 2006
posts: 3123
votes: 0

RewriteRule ^mukilteo.*$ roofers-mukilteo.php

Note that this is an "internal rewrite", not an "external redirect". The URL does not change in the address bar, the user is not actually redirected anywhere.

Rewriting/redirecting to a relative path can be problematic and this is likely to be the cause of your problem when you change this to a redirect (by adding the R flag).

This can be resolved with the RewriteBase directive (which controls what path is used in a relative path substitution), however, I think it would be preferable to make the substitution root-relative instead. Or, to avoid any ambiguity, make it absolute...

RewriteRule ^mukilteo http://example.com/roofers-mukilteo.php [R]

Note that this is a temporary (302) redirect. For a permanent redirect you need to state the code ie. [R=301]. I've also simplified the RewriteRule pattern by removing the end marker (
is superfluous).