Welcome to WebmasterWorld Guest from 54.226.22.192

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Strip Query String Only from One Script

     
9:37 pm on Jul 2, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 23, 2007
posts:48
votes: 0


Hello,

I have searched through the forum here but haven't been able to figure out my rewrite rule.

I have a script located at http://www.example.com/scripts/do_something.php

I'd like to strip all parameters from do_something.php so that:

http://www.example.com/scripts/do_something.php?name=filename&location=loc&blah=blah

301 redirects to

http://www.example.com/scripts/do_something.php

I do not, however, want any other scripts with query strings to be stripped, only do_something.php.

Thanks!

10:09 pm on July 2, 2008 (gmt 0)

Senior Member

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

joined:Mar 31, 2002
posts:25430
votes: 0


This is a fairly simple mod_rewrite. Please post your best-effort code as a basis for discussion. See our forum charter for more information.

Thanks,
Jim

2:06 am on July 3, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 23, 2007
posts:48
votes: 0


I have tried:

RewriteCond %{query_string} .
rewriterule (.*) http://www.example.com/$1? [R=301,L]

but this strips query strings from all files, not just the do_something.php file.

Then I tried:

RewriteCond %{query_string} .
rewriterule ^scripts/do_something.php?name=(.*) http://www.example.com/scripts/do_something.php$ [R=301,L]

And many more variations of the above two. I seem to create an infinite redirect often because I am redirecting from do_something.php with query strings to do_something.php without query strings.

2:26 am on July 3, 2008 (gmt 0)

Senior Member

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

joined:Nov 12, 2005
posts:5966
votes: 0


Try:

RewriteRule ^/scripts/do_something\.php\?.+$ /scripts/do_something.php [R=301,L]
2:40 am on July 3, 2008 (gmt 0)

Senior Member

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

joined:Mar 31, 2002
posts:25430
votes: 0


Assuming this code goes in .htaccess and not in a server config file, you almost got it, actually:

RewriteCond %{QUERY_STRING} .
RewriteRule ^scripts/do_something\.ph[b]p$[/b] http://www.example.com/scripts/do_something.ph[b]p?[/b] [R=301,L]

A query string is never visible to RewriteRule, so a RewriteCond must be used, and the "?" at the end of the substitution URL is the operator that actually clears the query string; Without that operator, the query string will be passed-through the rule unchanged.

Jim

7:19 am on July 3, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 23, 2007
posts:48
votes: 0


you know with programming, you can be so close ("almost got it") yet so far unless you have some help. thank you for the help!
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members