homepage Welcome to WebmasterWorld Guest from 54.242.200.172
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Strip Query String Only from One Script
suga




msg:3688905
 9:37 pm on Jul 2, 2008 (gmt 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!

 

jdMorgan




msg:3688934
 10:09 pm on Jul 2, 2008 (gmt 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

suga




msg:3689056
 2:06 am on Jul 3, 2008 (gmt 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.

eelixduppy




msg:3689071
 2:26 am on Jul 3, 2008 (gmt 0)

Try:

RewriteRule ^/scripts/do_something\.php\?.+$ /scripts/do_something.php [R=301,L]

jdMorgan




msg:3689077
 2:40 am on Jul 3, 2008 (gmt 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

suga




msg:3689216
 7:19 am on Jul 3, 2008 (gmt 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!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved