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

Apache Web Server Forum

    
Redirect without parameters
sam222



 
Msg#: 4471441 posted 6:39 am on Jul 1, 2012 (gmt 0)

My url is : http://example.com/mypage.php?Code=JI-MGH

when i use redirect rule as:
RewriteRule ^mypage.php$ /results/ [R=301,L]

It redirects to http://example.com/results/?Code=JI-MGH but parameter ?Code=JI-MGH is still coming with redirection. Can i have get a rid of ?Code=JI-MGH parameter so that i would be able to get only redirected url as:


http://example.com/results/

 

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4471441 posted 7:00 am on Jul 1, 2012 (gmt 0)

Your redirect is doing exactly what you're telling it to do.

:: shuffling papers ::

This is more than you wanted to know, but I don't feel like editing. Was woken up at ungodly hour by some species of evangelist pounding on the door. Grr.

Query Strings

The Query String, also known as a Parameter, is the part of an url after the question mark. Question = query.

By default, rewrites simply ignore the query string. That is, mod_rewrite stashes the query in a safe place, does its stuff to the part before the question mark, and then reappends the original query.

Changing a Query

#1 To delete a query, add a ? to the end of your rewrite target.
#2 To replace a query—or create a new one—add ?blahblah to the rewrite target. The blahblah can be either literal text, or stuff you captured earlier. (#1 and #2 are really the same thing: you're just replacing the query with either something or nothing.)
#3 To add to an existing query, again put ?blahblah at the end of the target, but also add [QSA] to your flags (the bracketed items at the end of the Rule). It stands for "Query String Append", meaning that the blahblah is to be added to the existing query—if any—instead of replacing it.

Getting the Query

You only need to retrieve the original query if
#1 you want the rewrite to behave differently depending on what the query was
or
#2 you need to change or delete the query

Add a Condition that says

RewriteCond %{QUERY_STRING} blahblah

using your ordinary Regular Expressions, anchors and ! as needed.

To test whether there was a query at all

RewriteCond %{QUERY_STRING} .

which simply means "If the query contains at least one character of any kind".

If you need to capture any of the query, use parentheses as usual. In the rewrite target, the captures will be %1, %2 etc instead of $1, $2 etc, because they are coming from a Condition instead of the Rule. Each set is separately numbered, so the first capture from the Rule will still be $1.

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4471441 posted 7:02 am on Jul 1, 2012 (gmt 0)

Escape the literal period in the rule pattern.

Add the protocol and domain name to the start of the rule target.

Add a question mark to the end of the rule target to suppress parameters.

sam222



 
Msg#: 4471441 posted 7:43 am on Jul 1, 2012 (gmt 0)

Could you please write me an example. Many thanks.

sam222



 
Msg#: 4471441 posted 7:46 am on Jul 1, 2012 (gmt 0)

Thanks g1smd, i have tried as you said it worked like a charm :)

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4471441 posted 7:47 am on Jul 1, 2012 (gmt 0)

Let's see the full code.

sam222



 
Msg#: 4471441 posted 7:51 am on Jul 1, 2012 (gmt 0)

I have done like:
RewriteRule ^mypage.php$ /results/? [R=301,L]

It worked fine in firefox and chrome but in IE it is still an issue.

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4471441 posted 7:53 am on Jul 1, 2012 (gmt 0)

Escape the literal period in the rule pattern.

Add the protocol and domain name to the start of the rule target.

sam222



 
Msg#: 4471441 posted 8:18 am on Jul 1, 2012 (gmt 0)

Could you please tweak this:

RewriteRule ^mypage.php$ /results/? [R=301,L]

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4471441 posted 9:04 am on Jul 1, 2012 (gmt 0)

It worked fine in firefox and chrome but in IE it is still an issue.

This is, on the face of it, impossible. Browsers simply place orders; the server fills them.

But wasn't there a recent thread that discussed something vaguely analogous? I think the conclusion is that if it's only working in some browsers, it really isn't working in any browser: it's just that some browsers are independently doing things that make it seem to be working.

Since you've got firefox, what does Live Headers say?

Could you please tweak this:

RewriteRule ^mypage.php$ /results/? [R=301,L]


As g1 said: Escape any literal periods in the pattern. Use the complete protocol and domain name in the target.

incrediBILL

WebmasterWorld Administrator incredibill us a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



 
Msg#: 4471441 posted 5:25 am on Jul 2, 2012 (gmt 0)

You keep missing what G1 said, I believe he wants it to look like this:

RewriteRule ^mypage\.php$ /results/? [R=301,L]

Try that.

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4471441 posted 5:52 am on Jul 2, 2012 (gmt 0)

:: cough, cough ::
Add the protocol and domain name to the start of the rule target.


And I'm still curious about the different behavior in different browsers. Something tells me one of them is being too smart for its own good. (It pains me horribly to say it, but in this specific case I don't think MSIE is doing anything wrong ;))

sam222



 
Msg#: 4471441 posted 6:29 am on Jul 2, 2012 (gmt 0)

Still no luck i have modified the rule as G1 said.

sam222



 
Msg#: 4471441 posted 6:33 am on Jul 2, 2012 (gmt 0)

Sorry to keep on bothering guys, i have refreshed my IE cache and it worked this time. Thanks for all kind supports. Wonderfull forum :)

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.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved