Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

301 redirect messed with rewrite rule



12:21 pm on Feb 6, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

I know this must have an answer somewhere around here, but I am unable to find/locate it.

There is a typical 301 redirection rule in the same domain:
Redirect 301 /path/to/strange-url.htm /path/to/new/canonical-url.htm

Later on htaccess file, there is a rewrite rule for the canonical-url
RewriteRule ^([^/]+)/([^/]+)([^/]+)/([^-]+)-([^.]+)\.htm$ php/page.php?var1=$1&var2=$2&var3=$3&var4=$4&var5=$5 [NC,L]

Problem is that as soon as the 301 redirect activates, my new url becomes:

I tried the following, to prevent unnecessary loops, but it didn't worked:
RewriteCond %{REQUEST_URI} !^php/page.php
RewriteRule ^([^/]+)/([^/]+)([^/]+)/([^-]+)-([^.]+)\.htm?$ php/page.php?var1=$1&var2=$2&var3=$3&var4=$4&var5=$5 [NC,L]

How can I avoid this and maintain only the clean url?


12:48 pm on Feb 6, 2013 (gmt 0)

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

If the redirect runs after the internal rewrite, then the previously rewritten internal filepath is exposed back out on the web as a new URL.

NEVER mix Redirect or RedirectMatch and RewriteRule in the same htaccess file.

Change all of the redirects to use RewriteRule syntax. The target URL of the redirect should include both the protocol and hostname too.

Make sure the redirects are listed before the rewrites.

Within each group, list from most specific to most general. The non-www/www canonicalisation redirect rule will be the last redirecting rule, and listed just before the first of the rewrites.

This will most likely fix your issues.

To suppress parameters on a redirect (when using a RewriteRule for the redirect) add a question mark to the end of the target URL.

Begin the target of each internal rewrite with a leading slash to prevent path injection especially when that target begins $1 or %1.


3:03 pm on Feb 6, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

well that worked
- changed all Redirect 301 to RewriteRule [R=301,L]
- moved all former redirects before the actual rewrites

thank you for your assistance!

Featured Threads

Hot Threads This Week

Hot Threads This Month