Forum Moderators: phranque

Message Too Old, No Replies

Issue with query string

         

CainIV

7:00 am on Oct 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello guys, I am trying to 301 all previously paged and dynamic versions of a websitesite url which used the root php file in the filename and this is what I have come up with:

RewriteCond %{QUERY_STRING} &?[a-z] [NC]
RewriteRule ^index\.php$ [my-site.com...] [R=301,L]

I do not want anyone to write the code, I would just like assistance so that I can fix this myself.

Using this code I am trying to redirect anything using index.php followed immediately by a question mark only (index.php?), as some urls are indexed as index.php/someothername/

I realize to redirect numeric queries I will need to add that as well, but so far I would like to start by getting this working first.

Much Regards,
Todd

CainIV

7:13 am on Oct 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry guys, not need, I found the solution by putting a couple of JD's posts together

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?category_name=(.*)\ HTTP/
RewriteRule ^index\.php$ [mysite.com...] [R=301,L]

Thanks for the help on this forum JD.

jdMorgan

3:50 pm on Oct 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That'll run faster with a more-specific pattern in the RewriteCond:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?category_name=([^\ ]*)\ HTTP/

Otherwise, the regex parser will have to retry n times for a match, where n is the number of characters in the request following "name=".

As shown, the pattern will match anything after "name=", up to the first space that it finds.

You could also use ([^&\ ]+) to match up to the next space OR query-string parameter, if there is a chance you will ever have more than one parameter -- Or that someone might try to cause you trouble by adding fake query string parameters in a link.

Jim