Welcome to WebmasterWorld Guest from 54.147.134.218

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

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

Full Member

10+ Year Member

joined:May 25, 2005
posts:220
votes: 0


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?

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

Senior Member

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

joined:July 3, 2002
posts:18903
votes: 0


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.

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

Full Member

10+ Year Member

joined:May 25, 2005
posts:220
votes: 0


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?

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

Senior Member

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

joined:July 3, 2002
posts:18903
votes: 0


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?

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

Full Member

10+ Year Member

joined:May 25, 2005
posts:220
votes: 0


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.

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

Senior Member

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

joined:July 3, 2002
posts:18903
votes: 0


RewriteRule cannot directly see the query string parameters.

You need a RewriteCond that examines QUERY_STRING for this.

1:15 am on Apr 19, 2009 (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


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

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

Full Member

10+ Year Member

joined:May 25, 2005
posts:220
votes: 0


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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members