Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Redirection and Rewrite rules clashing



9:46 am on Jan 10, 2007 (gmt 0)

5+ Year Member

I have some rewrite rules like this

RewriteRule ^/?([-A-Za-z0-9]+)/?$ index.php?sectionname=$1 [L]
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/?$ index.php?sectionname=$1&categoryname=$2 [L]
^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/([A-Za-z0-9-]+)/?$ index.php?sectionname=$1&categoryname=$2&title=$3 [L]

This rule

RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/?$ index.php?sectionname=$1&categoryname=$2 [L]

rewrites a url to this


The problem that I have is that I have some old pages that I need to redirect to these new pages that I have rewritten urls for

My old page that i want to redirect is like this


and I want to redirect it to my new page


It wont work, and seems to add the full url to the end after the slash
like this


I have tried everything. It seems that the rewrite and redirect clash due to them workin on the same part of the URL (between the slashes)

I would be really grateful for any tips on how to get around this issue.

Or is there a better way than using htaccess to rewrite?



3:09 pm on Jan 10, 2007 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

May we see the "tv/video" redirect, in context along with the rewrites, please?

This is likely a problem of rule order and/or mixing directives from mod_rewrite and mod_alias and expecting them to execute in line-by-line order, which they may or may not do, depending on your server configuration.

Also, what version of Apache are you on?



10:38 am on Jan 11, 2007 (gmt 0)

5+ Year Member


Many thanks for your help

Here is my full htaccess file

I have to put some words in between the slashes to make sure the rewrites work, so this doesnt work as it stands at the moment.

For instance: ([-A-Za-z0-9]+)my-product-page

RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)my-product-page/?$ index.php?sectionname=$1&categoryname=$2 [L]

I didnt realise the order in which they appear would matter. Is it possible to not have any of these rules clashing at all then? And will it be possible for me not to use the "my-product-page" in the URL?

Again many thanks for your help :)


Options +FollowSymLinks
RewriteEngine On

RewriteRule ^_([-A-Za-z0-9]+)/?$ index.php?page=$1 [L]
RewriteRule ^/?([-A-Za-z0-9]+)/?$ index.php?sectionname=$1 [L]
RewriteRule ^/?([-A-Za-z0-9]+)/_([-A-Za-z0-9]+)/?$ index.php?sectionname=$1&page=$2 [L]
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/?$ index.php?sectionname=$1&categoryname=$2 [L]
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/_([-A-Za-z0-9]+)/?$ index.php?sectionname=$1&categoryname=$2&page=$3 [L]

## This seems to be the problem line, when I remove it the redirect works.
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/([A-Za-z0-9-]+)/?$ index.php?sectionname=$1&categoryname=$2&title=$3 [L]

RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/([A-Za-z0-9]+)-([-A-Za-z0-9]+)/?$ index.php?sectionname=$1&categoryname=$2&ordertype=$3 [L]
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/([A-Za-z0-9]+)/_([-A-Za-z0-9]+)/?$ index.php?sectionname=$1&categoryname=$2&ordertype=$3&page=$4 [L]

RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/([A-Za-z0-9]+)-([-A-Za-z0-9]+)/?$ index.php?sectionname=$1&categoryname=$2&filterfield=$3&filter=$4 [L]
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/([A-Za-z0-9]+)-([-A-Za-z0-9]+)/_([A-Za-z0-9]+)/?$ index.php?sectionname=$1&categoryname=$2&filterfield=$3&filter=$4&page=$5 [L]

RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/([A-Za-z0-9]+)-([-A-Za-z0-9]+)/([A-Za-z0-9]+)-([-A-Za-z0-9]+)/?$ index.php?sectionname=$1&categoryname=$2&filterfield=$3&filter=$4&ordertype=$5&filter=$6 [L]
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/([A-Za-z0-9]+)-([-A-Za-z0-9]+)/([A-Za-z0-9]+)-([-A-Za-z0-9]+)/_([A-Za-z0-9]+)/?$ index.php?sectionname=$1&categoryname=$2&filterfield=$3&filter=$4&ordertype=$5&filter=$6&page=$7

RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule .index.php

Redirect 301 /tv/video http://www.mydomain.com/newtv/newvideo


12:52 pm on Jan 11, 2007 (gmt 0)

5+ Year Member

P.S. My Apache version is Apache 2.0.59


3:08 pm on Jan 12, 2007 (gmt 0)

5+ Year Member

Please.... need help..... got to... find ... and answer to this problem.....

Sorry for talking in He-man language, but I would really be grateful for anyone to chip in as I have no clue how to solve this problem



3:51 pm on Jan 12, 2007 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

The problem here is that the size of the code discourages discussion, and also interferes with your own ability to figure it out.

This may not be a coding problem at all -- it may simply be that there is a logical inconsistency buried in all those "slashes and dashes" that is causing unexpected operation. The "visual clutter" makes it very hard for anyone not intimately familiar with your URL-patterns to discern.

Short, focused questions generally get quicker responses, while long code dumps may have to wait for the weekend...

By using directives from two modules -- both mod_rewrite and mod_alias, you lose control over which directives are processed first. I'd suggest re-coding that redirect using mod_rewrite, and placing it above your other rules:

RewriteRule ^tv/video(.*)$ http://www.example.com/newtv/newvideo$1 [R=301,L]



4:59 pm on Jan 12, 2007 (gmt 0)

5+ Year Member

Thanks so much JD, you totally solved my problem.

Point taken about the long posts, I will try and be more succinct next time.

Cheers again :)


Featured Threads

Hot Threads This Week

Hot Threads This Month