Forum Moderators: phranque
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?
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.
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.
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]
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