Forum Moderators: phranque

Message Too Old, No Replies

permanent redirect of some pages to external site

         

frances

12:37 pm on Nov 4, 2004 (gmt 0)

10+ Year Member



Hello

I am trying to set up a permanent redirect of some pages from my site to an external (new) site (because I am paranoid about getting a duplicate content penalty from Google). I have been using mod_rewrite cos I am a little familiar with it.

The Rewriterules I have tried are:

^/index/([0-9]+)/foo\.htm$ [otherdomain.com...] [R=301,L]

^/index2/([0-9]+)/foo\.htm$ [otherdomain.com...] [R=301,L]

but both generate a page not found error. The pattern matching works OK I know because its been in use on the site for some time.

So the problem must be (?) the redirection to external url.

Does anyone know if there are any server settings that might need to be changed?

Or could the problem be that the Rewritebase is / (though it doesnt look that way from the Apache docs)?

Both sites are on the same server if that makes any difference.

Would really appreciate some help.

jdMorgan

4:56 pm on Nov 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



frances,

As written, your code appears to be for use in httpd.conf, and not in .htaccess. Is this correct?

You must precede the code with RewriteEngine on, and some servers will require you to precede that with Options +FollowSymLinks or Options +SymLinksIfOwnerMatch.


^/index/([0-9]+)/foo\.htm$ http://www.otherdomain.com/foo/$1.htm [R=301,L]

This rule will redirect the file "foo.html" only when it is requested from subdirectory /index/<any number of digits./

It will redirect that request to "www.otherdomain.com/foo/<digits from original request>.htm"

If both domains resolve to the same "account" on the same server, you will have to be careful not to create an infinite redirection loop. If this is the case, use RewriteCond to test %{HTTP_HOST} in order to prevent looping after the first redirect has been followed.

I am trying to fill in information here that you left out. Please comment on any omissions or correct any errors in order to get more helpful replies.

Jim

frances

6:25 pm on Nov 4, 2004 (gmt 0)

10+ Year Member



Hi Jim

Sorry for not being clear.

The code is in .htaccess, it is preceded by RewriteEngine on, and Options +FollowSymLinks, and the pattern matching you outlined for the redirect is correct. But although the pattern matches, the redirect doesnt. It just brings up a file not found page.

I dont know if both domains resolve to the same "acount" on the server. This may well be the case. Both sites are from the same company. The sever people (its a shared server) are supposed to be setting up a separate IP address but they are hard to contact. I have asked them a few times this week about this problem but they have yet to reply.

I will look into what using RewriteCond to test %{HTTP_HOST} implies and see if that helps.

If you have any other suggestions, I would appreciate it.

Thanks

Frances

jdMorgan

6:56 pm on Nov 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't think your code will work in .htaccess, because the leading slash will be stripped. So try:

RewriteRule [b]^i[/b]ndex/([0-9]+)/foo\.htm$ http://www.otherdomain.com/foo/$1.htm [R=301,L]
RewriteRule [b]^i[/b]ndex2/[0-9]+/foo\.htm$ http://www.otherdomain.com/ [R=301,L]

Jim

frances

11:02 pm on Nov 4, 2004 (gmt 0)

10+ Year Member



Tried this code:

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\.originalDomain\.com
RewriteRule ^index/([0-9]+)/foo\.htm$ [otherdomain.com...] [R=301,L]

and got the same page not found message - which is the custom page _not_found of www.originalDomain.com which I guess means the request is not being redirected at all.

Not quite sure what the rewritecond is doing, but scared of removing it in case it is preventing an infinite loop.

I wish I knew what was going on here.

jdMorgan

12:54 am on Nov 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, that RewriteCond prevents the RewriteRule from being applied to requests for pages in the original domain, so it rather defeats the purpose...

Advice: Don't add code you don't understand. Some time spent studying the references cited in our charter [webmasterworld.com] might be worthwhile. If you have a loop problem, it can easily be fixed *after* getting the redirect to work. If you are working on a live server, then use test pages and test URLs so as not to disturb current users. Even the worst redirect loop won't crash the server.

Jim

frances

1:14 am on Nov 5, 2004 (gmt 0)

10+ Year Member



sorry if I sound lazy but I have spent hours (truly) searching on this site, experts exchange, reading the apache mod-rewrite documentation etc I searched on infinite loops and found not too much that made sense to me. (A lot of the stuff assumes prior knowledge that I dont have). I also have made about 50 (100?) .htaccess code tests. I didnt come here before doing any homework but after.

I will keep on looking, but any help would still be appreciated.

jdMorgan

1:21 am on Nov 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What were the results of testing the code in msg#4?

This should not be a very hard problem to debug, if we stay on-track.

Jim

frances

2:17 am on Nov 5, 2004 (gmt 0)

10+ Year Member



Thanks - and sorry - and..... it worked!

I'm unbelievably grateful. The stupid thing is - I had no slash at the beginning in the rewrite rules I had going on within the site that have been working for months. It was only by reading and copying suggestions that the forward slash appeared...

Whatever, I really appreciate your help. Thanks a lot.