Forum Moderators: phranque

Message Too Old, No Replies

Redirect subdomain to a new domain

redirect htaccess rewrite

         

mhamdi

1:45 am on Dec 3, 2007 (gmt 0)

10+ Year Member



Hello,
I want to perform a redirection to but I can't get it to work. I want to simply redirect forum.domain.com to forum.domain.net
Here is what I am using but the server is ignoring.

RewriteEngine On
RewriteBase /

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

Do you know what I am doing wrong, btw I have other rewrite rules placed after that rule like redirecting non www to www and works fine.

[edited by: jdMorgan at 2:10 am (utc) on Dec. 3, 2007]
[edit reason] example.com [/edit]

jdMorgan

2:30 pm on Dec 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Two things to check:

First, be sure that the code is in an .htaccess file that will be executed as the server traverses the filepath to reach the directory where the forum files are located. That is, if forum.example.com files are located in a separate directory which is not "below" the directory containing this rule, then this rule won't apply to requests for that subdomain.

Second, be sure to completely flush your browser cache before testing after uploading any changed configuration code to your server.

Jim

mhamdi

3:50 pm on Dec 3, 2007 (gmt 0)

10+ Year Member



Actually there is no forum folder I just want to redirect those requests to the other domain. (forum.example.com -> forum.example.net without actually having forum folder in .com)
What I did as a temporary solution is to actually create the subdomain and add a .htaccess in that folder to make the redirection. Not very practical as I need to make the same thing for around 10 subdomains.

jdMorgan

4:35 pm on Dec 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This indicates that the 'logic' in httpd.conf that 'steers' subdomains to your filespace is probably checking the requested subdomain in the HTTP Host request header, and won't send subdomain requests to your main space in the absence of a defined (as you said, 'created') subdomain.

Jim

mhamdi

4:59 pm on Dec 3, 2007 (gmt 0)

10+ Year Member



Jim, I have access to httpd.conf for the site and the server. Is there a way I can change this.
Thanks

jdMorgan

5:26 pm on Dec 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can add a <ServerAlias> directive using the wild-card "*.example.com" so that all subdomains are steered toward one filespace, and then put the mod_rewrite code in that space. Or, with some minor tweaks, you could put the code inside the <ServerName> container in httpd.conf itself.

The main difference between mod_rewrite code in .htaccess and in http.conf is that the URL-pattern in RewriteRule should include a leading slash in httpd.conf, but not in .htaccess.

Jim