homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

R flag breaking redirect in .htaccess

Msg#: 4694957 posted 10:41 pm on Aug 12, 2014 (gmt 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?



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

Msg#: 4694957 posted 11:08 pm on Aug 12, 2014 (gmt 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).
Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved