Forum Moderators: phranque

Message Too Old, No Replies

Redirect 301 from apache

Mirror sites

         

seopeople

10:27 am on Sep 10, 2008 (gmt 0)

10+ Year Member



I'll try to explain my question as simply as possible...

Webserver is apache.

There's a website, we'll call it A.
A's URL is http://www.example.com/~subdir

A has an alias at http://subdomain.example.com which contains a pointer to the original URL so that it points to the same folder in the same server.

Now, I would like to create a 301 redirect from all URLs under http://www.example.com/~subdir to the same URLs under http://subdomain.example.com

For security reasons, I can place the .htaccess file only under http://www.example.com/~subdir. I couldn't find the right syntax for .htaccess.

I've tried:

Redirect 301 /page.html http://www.example.com/page.html: Created a server error

Redirect 301 http://www.example.com/~subdir/page.html http://subdomain.example.com: Did nothing at all

Can you please help me and find the right solution?

Thank you.

[edited by: encyclo at 4:30 pm (utc) on Sep. 10, 2008]
[edit reason] switched to example.com [/edit]

seopeople

5:15 am on Sep 14, 2008 (gmt 0)

10+ Year Member



I would really appreciate an answer. Is there a more suitable forum for this question?

Thanks.

jdMorgan

8:42 am on Sep 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is the correct forum, but you may have it confused with an instant messaging service or something... We get a bit slow on weekends, late-night in the U.S., and after major hurricanes, etc.

I would guess that the problem is that you are not basing the redirect on the requested hostname, which is why your first Redirect (which is properly-coded) did not work -- Had you looked at your server error log, it's likely that it would have indicated that an infinite loop had been detected.

Use mod_rewrite, and use a RewriteCond to examine the HTTP_HOST variable and invoke the redirect only if it indicates that the current request was to the example.com domain. In other words, you don't want to redirect again if you've already been redirected to subdomain.example.com, and since both domain variants are in the same space on the same server, a stand-alone mod_alias Redirect directive can't be used without creating a redirection loop.

Jim