Welcome to WebmasterWorld Guest from 54.162.167.40

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)



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)

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



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).
 

Featured Threads

Hot Threads This Week

Hot Threads This Month