Welcome to WebmasterWorld Guest from 54.159.26.69

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Redirecting a dynamic url containing Question Mark

Dynamic URL contains a "?" but having problems redirecting

     

chopin2256

8:50 pm on Apr 18, 2009 (gmt 0)

10+ Year Member



I am trying to redirect just this particular dynamic URL from the www version, to the subdomain version.

An example of the page I want to redirect looks like this:

www.example.com/wiki/index.php?title=Page_Name&action=edit

to...

wiki.example.com/wiki/index.php?title=Page_Name&action=edit

I tried this code, but it doesn't seem to be working:


RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^wiki/index.php?title=Page_Name&action=edit$ "http\:\/\/wiki\.example\.com\/wiki\/index\.php\?title\=Page_Name\&action\=edit" [R=301,L]

Can anyone help me?

g1smd

9:23 pm on Apr 18, 2009 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



The \: and \/ and \. and \= syntax is wrong. You only need : or / or . or = in the target URL.

The URL, as visible to the rule (for matching in the pattern), does not contain the query string. You need another RewriteCond to look at that.

Your existing RewriteCond is redundant, or might need modifying to prevent a loop.

chopin2256

10:19 pm on Apr 18, 2009 (gmt 0)

10+ Year Member



How about something like this:

RewriteCond %{HTTP_HOST} ^(www.example.com/wiki/index.php?title=Page_Name&action=edit$) [NC]
RewriteRule ^(.*)$ http:\\wiki.example.com/wiki/index.php?title=Page_Name&action=edit [R=301,L]

Still not working, but is this a better direction?

g1smd

10:28 pm on Apr 18, 2009 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



This is closer, but HTTP_HOST only sees the domain name.

You'll also need to look at QUERY_STRING to evaluate that.

Does the Rule need to look at every (.*) URL on your site?

chopin2256

11:54 pm on Apr 18, 2009 (gmt 0)

10+ Year Member



The rule just needs to do a simple redirect of one page. I am having a hard time redirecting the page with the question mark in it :/ This simple rule is all I need:

RewriteRule ^wiki/index.php?title=Page_Name&action=edit $ [wiki.example.com...] [L,R=301]

The question mark throws this off though, even if I try to escape it.

g1smd

12:31 am on Apr 19, 2009 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



RewriteRule cannot directly see the query string parameters.

You need a RewriteCond that examines QUERY_STRING for this.

jdMorgan

1:15 am on Apr 19, 2009 (gmt 0)

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



All the information needed to make a working rule has been posted above, assuming that you refer to the Apache mod_rewrite documentation [httpd.apache.org]:

RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteCond %{QUERY_STRING} &?title=Page_Name&action=edit&?
RewriteRule ^wiki/index\.php$ http://wiki.example.com/wiki/index.php?title=Page_Name&action=edit [R=301,L]

Once that works, you may want to reconsider whether you really want to include the /wiki/index.php part in the URL: It would likely be easy (and better for users and search engines) to use a URL of wiki.example.com/?title=Page_Name&action=edit to refer to the file at /wiki/index.php.

There is simply no reason to "expose" the "file storage area" for your "wiki" subdomain in the URL. It makes correctly hearing, writing, remembering, and saying the URL that much more difficult, and is usually not necessary.

Note that the two "&?" subpatterns are "soft anchors, intended to prevent a match on a possible query of "subtitle=Page_Name&action=edit" or "title=Page_Name&action=edit-undo". Might save quite a bit of trouble in the future.

Jim

chopin2256

3:22 am on Apr 19, 2009 (gmt 0)

10+ Year Member



Thank you all for your help. I wasn't aware that rewrite rules cannot see query string parameters, whoops. This problem has been solved :)
 

Featured Threads

Hot Threads This Week

Hot Threads This Month