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