views:

32

answers:

1

I have a set of rewrite rules that are supposed to process a URL that has anywhere from 1 to 5 parameters. So my URL might look like this: www.site.com/topic1/page1 or www.site.com/topic1/sub1/page1.

Here are my rules in this example:

RewriteRule ^([^/.]+)/?$ /staticpages/process-selection.php?param1=$1 [E=rwdone:yes,L]
RewriteRule ^([^/.]+)/([^/.]+)/?$ /staticpages/process-selection.php?param1=$1&param2=$2 [E=rwdone:yes,L]
RewriteRule ^([^/.]+)/([^/.]+)/([^/]+)/?$ /staticpages/process-selection.php?param1=$1&param2=$2&param3=$3 [E=rwdone:yes,L]
RewriteRule ^([^/.]+)/([^/.]+)/([^/]+)/([^/]+)/?$ /staticpages/process-selection.php?param1=$1&param2=$2&param3=$3&param4=$4 [E=rwdone:yes,L]
RewriteRule ^([^/.]+)/([^/.]+)/([^/]+)/([^/]+)/([^/]+)/?$ /staticpages/process-selection.php?param1=$1&param2=$2&param3=$3&param4=$4&param5=$5 [E=rwdone:yes,L]

To complicate matters, I might have a redirect 301 from an old URL to one of these new URLs. So "/topic1/page1/oldpage" might first get re-directed to "/topic1/page1/newpage".

For some reason, when the rewrite occurs, the URL that shows up in the browser has the correct URL, but with the old variables appended to the url like this: /topic1/page1/newpage?param1=page1&param2=oldpage

I'm wondering if there's any way to avoid this situation. what the heck am I doing wrong here.

A: 

mod_alias works later then mod_rewrite, and the [L] flag is only valid for mod_rewrite rules, not mod_alias (i.e. those rules would still be applied to the original URL, but strangely enough apparently with the new querystring). To enable mod_alias to see the already rewritten url, use the [PT] flag, or alternatively try to do all rewriting / redirecting with mod_rewrite.

Wrikken
Thanks very much for your input. I was able to solve the problem by changing my redirect 301 code to RewriteRule ^url [R=301,L]. Finally not seeing strange parameters appended to my browser urls.
Bill