Forum Moderators: phranque

Message Too Old, No Replies

Rewrite rule doesn't pass query string with QSA

QSA flag seems to be ignored on rewrite rule.

         

authcode

3:12 pm on Jan 5, 2008 (gmt 0)

10+ Year Member



Hi,

Like others here I've learned a lot from these forums and have managed to muddle through until now. I've recently come up against a problem I just can't see a solution to and desperately need help!

I'm doing some fairly basic url rewriting:

RewriteEngine on

#CLUB REWRITE
RewriteRule ^club/([^/]+)$ /virtual/club/index.php?clubName=$1 [QSA,L]
RewriteRule ^club/(.*)/(.*)$ /virtual/club/$2?clubName=$1 [QSA,L]

The first rule handles url requests of:
http://www.example.com/club/myclub
and
http://www.example.com/club/myclub/

The second rule handles url requests of:
http://www.example.com/club/myclub/somepage.php

This all works. My problem is I want to use URLs like:
http://www.example.com/club/myclub/somepage.php?myvar=1
so that this page is served:
http://www.example.com/virtual/club/somepage.php?myvar=1&clubName=myclub

I recently came across the QSA flag and thought I'd cracked it but it still just not seem to pass the requested query string, only the "clubName". What am I doing wrong? Are there any cases (versions, settings etc.) in which QSA does not work? And, finally, is there a better way to achieve this goal?

Any help would be very much appreciated!
Stephen.

jdMorgan

4:08 am on Jan 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your rules should work as you expect them to -- The 'incoming' query should be combined with your added query string parameters. It should just work.

You might want to check with your host to make sure the Apache installation isn't corrupt -- or isn't a really old version... Can't think of any reason why your code wouldn't work.

If you're stuck with that host, you could try a "manual" work-around -- essentially duplicating the [QSA] function:


RewriteCond %{QUERY_STRING}& ^((.+&)¦&)$
RewriteRule ^club/([^/]+)/([^/]+)$ /virtual/club/$2?%2clubName=$1 [L]

Replace the broken pipe "¦" character above with a solid pipe from your keyboard before use; Posting on this forum modifies the pipe character. The code is arranged so that %2 will either contain the initial query string value plus an ampersand, or it will be completely blank if there was no initial query string. In either case, the RewriteCond is always 'true' and the rule will execute if its pattern is matched.

Jim

authcode

12:14 pm on Jan 6, 2008 (gmt 0)

10+ Year Member



Many thanks Jim.

My host is running Apache version 1.3.39 (Unix), I'm not sure if that is considered old?

I'll contact support about this QSA issue and if they discover anything useful I'll update this thread for anyone else that might need it. In the meantime your suggested workaround is exactly what I need so I'll give it a go.

Thanks again,
Stephen