Forum Moderators: phranque

Message Too Old, No Replies

strip query string

         

nordoutlet

5:19 pm on Mar 22, 2010 (gmt 0)

10+ Year Member



Moved to a new domain and wanna create redirect, so

index.php/PublishedService?file=page&pageID=9&itemcode=bla-bla

will direct to

search.php?search_query=bla-bla

I tried two rules:
RewriteRule ^index.php/(.*)$ /search.php?search_query=$1 [R=301,L]

and

RewriteRule ^index.php/PublishedService?file=(.*)&pageID=(.*)&itemcode=(.*)$ /search.php?search_query=$3 [R=301,L]

The first rule results searcing for 'PublishedService', the second one does nothing.

I have spent 5 hours on this and this is all I have achhieved so far. What have I done wrong here?

jdMorgan

5:27 pm on Mar 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use a RewriteCond to check the query string in %{QUERY_STRING}. RewriteRule can't see anything but the URL-path.

Jim

nordoutlet

5:34 pm on Mar 22, 2010 (gmt 0)

10+ Year Member



doesn't work this way also:

RewriteCond %{QUERY_STRING} itemcode=(.*)
RewriteRule ^index.php/PublishedService?file=page&pageID=9&itemcode=$ /search.php?search_query=$1 [R=301,L]

g1smd

12:11 am on Mar 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You'll need %1 not $1 in the target.

Again, RewriteRule cannot see anything other than the 'path' part of the URL. It cannot see the 'query string' data. It cannot see anything after the question mark.

With a redirect, you'll need to also mention the protocol and domain name in the target.

nordoutlet

1:34 am on Mar 23, 2010 (gmt 0)

10+ Year Member



Thank you, got it working now:

RewriteCond %{QUERY_STRING} ^file=page&pageID=9&itemcode=(.*)
RewriteRule ^index.php/(.*)$ http://www.example.com/search.php?search_query=%1 [R=301,L]

Could I improve it, index.php/(.*) - there is always 'PublishedService?' on (.*)?

[edited by: jdMorgan at 11:55 am (utc) on Mar 23, 2010]
[edit reason] example.com [/edit]

jdMorgan

11:58 am on Mar 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, make the RewriteRule and RewriteCond patterns as specific as possible. I'd suggest:

RewriteCond %{QUERY_STRING} ^file=page&pageID=9&itemcode=([^&]+)
RewriteRule ^index\.php/PublishedService$ http://www.example.com/search.php?search_query=%1 [R=301,L]

The question mark used to delimit the URL-path from the query string is not a part of either, and it will not be "visible" to either your RewriteRule or RewriteCond.

Jim

nordoutlet

5:45 pm on Mar 23, 2010 (gmt 0)

10+ Year Member



Thank you, Jim, very much!

Just one more question:

RewriteCond %{QUERY_STRING} ^file=page&pageID=3&action=view&groupID=854&pagenr=([0-9])
RewriteRule ^index\.php/PublishedService$ http://www.example.com/23_guess [R=301,L]

It opens the target url but keeps the query string at the end, ie
http://www.example.com/23_guess?file=page&pageID=3&action=view&groupID=854&pagenr=1

How to get rid of it so there will be just the target address?

jdMorgan

5:59 pm on Mar 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Add a question mark to the end of the substitution URL. This will clear the query string.

Jim

nordoutlet

6:17 pm on Mar 23, 2010 (gmt 0)

10+ Year Member



Thank you once again, everything works perfectly!