Forum Moderators: phranque

Message Too Old, No Replies

.htaccess redirect issue

rss feed redirection

         

ancombgd

12:37 pm on Nov 1, 2011 (gmt 0)

10+ Year Member



Hello, this is my first post. I am pretty new to Apache configuration and I have the following problem: I have a website which we will call oldsite.com. On that site I have a blog, with address oldsite.com/oldblog, and its feed on address oldsite/oldblog/feed. My website will stay active, but I want to move blog to a new domain. The new address of blog feed will be newsite.com/newblog/feed. Could anyone tell me how should I redirect the blog feed and keep current subscribers, so when I post new content on new blog, subscribers on old blog feed could still see it.
Thanks in advance!

lucy24

11:00 pm on Nov 1, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What have you tried so far? What happens when you try it? (Details, please! "It doesn't work" is not enough information.)

g1smd

12:13 am on Nov 2, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You'll need a 301 redirect. Use a RewriteRule.

There's more than 30 000 previous threads in this forum with code for redirects.

ancombgd

1:16 am on Nov 2, 2011 (gmt 0)

10+ Year Member



Sorry if I was not clear enough. As I said, I am new to this stuff.
I would try with this code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^oldsite.com/oldblog/feed/$1
RewriteRule (.*) [newsite.com...] [R=301,L]

Am I totally wrong or will this work? I would apreciate any help.

g1smd

7:25 am on Nov 2, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



HTTP_HOST sees ONLY the requested host name, not the path.

Replace .* with the old path (sans leading slash) that you want to redirect.

Use example.com in this forum to prevent URL auto-linking.

ancombgd

11:09 am on Nov 2, 2011 (gmt 0)

10+ Year Member



Thank you, g1smd.
Did you mean something like this?

RewriteEngine On
RewriteCond %{HTTP_HOST} ^oldsite.com
RewriteRule (.oldsite.com/oldblog/feed/$1) http://example.com/newblog/feed/$1] [R=301,L]

lucy24

8:06 pm on Nov 2, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Oops, looks like you cut-and-pasted a little too fast. You've got $1 on both sides and an extraneous close-bracket. That is, I assume you don't want a bracket character at the end of your url.

Are the oldsite and newsite in different locations, using different htaccess files? If so, you don't need to specify a host unless the oldhost is sharing an htaccess with other, unrelated domains.

Only capture that part that you want to see repeated in the target. Otherwise you'll get

http://example.com/newblog/feed/.oldsite.com/oldblog/feed/$1

Escape all literal periods in the pattern. And get rid of that leading period . in the capture.

ancombgd

11:12 pm on Nov 2, 2011 (gmt 0)

10+ Year Member



Thank you, Lucy, for detailed explanation. Yes, I paste it in haste, I was late for work.
So, yes, domains are in different locations. I am trying to Google this stuff you explained, but I am still confused. If I got You right, only lines I need are (on old domain):
RewriteEngine On
RewriteRule (oldsite.com/oldblog/feed) http://example.com/newblog/feed/$1 [R=301,L]

g1smd

11:32 pm on Nov 2, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteRule pattern matching looks only at the path part of the request, not domain, port, nor query string.


@Lucy: Always specify the canonical domain name in every redirect. Without it, you open up the site to duplicate content problems:

example.com/foo redirects to example.com/bar
and
www.example.com/foo redirects to www.example.com/bar


Rules without domain in target also allow an unwanted redirection chain when there's also a non-www to www redirect in a separate rule:

example.com/foo => example.com/bar => www.example.com/bar
or
example.com/foo => www.example.com/foo => www.example.com/bar

ancombgd

12:04 am on Nov 3, 2011 (gmt 0)

10+ Year Member



This is my best shot:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^oldsite.com
RewriteRule (oldsite.com/oldblog/feed) http://example.com/newblog/feed [R=301,L]


@g1smd - for duplicate www content, I use this code:

RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Thank you all for taking time to explain, I am aware I have a lot to learn in this area.

lucy24

1:02 am on Nov 3, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Rules without domain in target also allow an unwanted redirection chain when there's also a non-www to www redirect in a separate rule

Yup. But I'm on shared hosting so I let them do the boring stuff like with/without and directory-slash redirects. (Matter of fact, I'm not sure I have any choice about the directory slash, unless I do some quick interception for specific cases.) So the logs really do show the 301-followed-by-403 pattern :) Well, it's their bandwidth. Or their RAM, or whatever is involved.

ancombgd, the www redirect should go after all other redirects. That way it picks up only those requests that haven't already been handled by other redirects.

If you are not reusing anything from the old text, you don't need to capture it. But wasn't there something after /feed/ that's variable? Remember that mod_rewrite does not reappend the rest of the path the way mod_alias (Redirect by that name) does.

g1smd

1:06 am on Nov 3, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Again, RewriteRule pattern matching sees only the PATH part of the request.

It does not "see" protocol, hostname, port, or query string.