Forum Moderators: phranque
I'm wanting to redirect certain pages from my old site to specific pages of my new site. The .htaccess file at my old site includes the following snippet which effectively redirects back to the root of the old site.
RewriteCond %{HTTP_HOST} ^oldsite.net$ [OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.net$
RewriteRule ^cms$ http://oldsite.net [R=301,L]
The above works, I merely mention this as this is what precedes what I want to do.
I've got the following redirection working
redirect 301 /node/509 http://newsite.org/node/23?
The above doesn't trap for htpp://oldsite.net/?=node/509, so I thought this would work, it doesn't.
redirect 301 /\?q=node/509 http://newsite.org/node/23?
I get 500 server errors when this is included.
How do I correctly write for the "?q=node/509" part. Also, when not including the question mark (?) at the end of the redirect line the redirect attempts to append the query part of the url. Including the ? the ? is visible in the newsite.net url, how do I removed the ? from the newsite page.
Any advice appreciated.
[edited by: jatar_k at 11:26 am (utc) on May 14, 2008]
[edit reason] delinked [/edit]
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^q=node/509$
RewriteRule ^$ http://newsite.org/node/23? [R=301,L]
To clarify, query strings are not part of a URL; They are data attached to a URL to be passed to the resource at that URL. Therefore, support is not always present, or implemented the way you might expect it to be.
Jim
[edited by: jdMorgan at 2:58 pm (utc) on May 15, 2008]
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.net
RewriteRule ^cms$ http://oldsite.net/ [R=301,L]
This hostname includes an optional dot after the tld, and an optional port number. Either or both are valid.
If you feel you must use an end-anchor then use this pattern:
(www\.)?oldsite.net.?(:[0-9]{1,5})?$
That allows for the optional dot and any valid port number. (You could also use (www\.)?oldsite.net.?(:80¦:433)?$
for just the common HTTP and HTTPS ports.)
Change the broken pipe character "¦" to a solid pipe before use; Posting on this forum modifies the pipe characters.
I also added an end-slash to the redirect URL to make it "correct" and avoid a server-internal redirect.
You should follow this rule with a general one to redirect *all* www.oldsite.net requests to oldsite.net, in order to avoid duplicate-content issues in search. Looking at your existing rule, I assume that you prefer the "non-www" domain, and that your non-www URLs have the most/best incoming links and rank best in search.
If you have no other subdomains except "www", then
RewriteCond %{HTTP_HOST} !^oldsite\.net$
RewriteRule (.*) http://oldsite.net/$1 [R=301,L]
Jim