Forum Moderators: phranque

Message Too Old, No Replies

How to re-direct a directory to new sub domain

Help required with .htaccess file

         

robinantill

11:36 am on Jan 11, 2012 (gmt 0)

10+ Year Member



I have a forum board on my main domain
http://www.example.com/support/ which I want to be redirected to a new sub domain I set up as follows:
http://www.sheds-support.example.com/

I am having trouble getting the .htaccess file to redirect http://www.example.com/support/ web pages to
http://www.sheds-support.example.com/ web pages

I tried loads of different configurations and none are working. At the moment I have this in my .htaccess file

RewriteEngine On
#RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com/support/ [NC]
RewriteRule ^(.*)$ http://www.sheds-support.example.com$1 [L,R=301]

The frustrating thing is that I had it working OK, however, when I was working on the .htaccess file for the sub-domain I went and copied over the main .htaccess file and I had not made a backup with the latest changes in. what a plank I am.

If any one could help I would be very grateful.
Regards,
Robin

[edited by: tedster at 5:25 pm (utc) on Jan 11, 2012]
[edit reason] switch to example.com [/edit]

robinantill

12:25 pm on Jan 11, 2012 (gmt 0)

10+ Year Member



I found my earlier .htaccess files and that works, thank goodness. This is as follows:

RedirectMatch 301 ^/support/(.*)$ http://sheds-support.example.com/$1

This is the code without the domain name in it:-

RedirectMatch 301 ^/support/(.*)$ domain.name/$1

Is there any issues with that which I'm missing, however, it does appear to be working fine?

[edited by: tedster at 5:26 pm (utc) on Jan 11, 2012]

phranque

3:04 pm on Jan 11, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



one problem with your first attempt is that %{HTTP_HOST} is not going to contain path information.

regarding your current solution, if you also are using mod_rewrite directives you could potentially have some compatibility issues with your mod_alias directives.

robinantill

7:22 pm on Jan 15, 2012 (gmt 0)

10+ Year Member



Apologies for not replying soon and thank you for your answer. I've tweaked the .htaccess which seems to have sorted my problem. Thanks again.

g1smd

7:41 pm on Jan 15, 2012 (gmt 0)

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



You need to use RewriteRule for your rules.

Let's see your latest code.

robinantill

8:53 pm on Jan 15, 2012 (gmt 0)

10+ Year Member



I'm using the following which appears to be working fine.

# THIS REDIRECT LINKS SUPPORT BOARD TO NEW LOCATION
RedirectMatch 301 ^/support/(.*)$ [sheds-support.leisurebuildings.com...]

Is there any reason I should not be using this?

g1smd

9:04 pm on Jan 15, 2012 (gmt 0)

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



Once your htaccess file contains both mod_alias (RedirectMatch) and mod_rewrite (RewriteRule) code you cannot guarantee what order the rules will be processed in.

They are processed in per-module order not in the order they are listed in the htaccess file. That can lead to an unwanted multiple step redirection chain for some requests.

Use example.com in this forum to prevent URL auto-linking. You don't want Google making requests for /$1 on your site.

robinantill

3:46 pm on Jan 16, 2012 (gmt 0)

10+ Year Member



Hi,
I did try the following:-
RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://www.leisurebuildings.com/support/ [NC]
RewriteRule ^(.*)$ [sheds-support.leisurebuildings.com$1...] [L,R=301]

AND

RewriteEngine On
RewriteCond %{HTTP_HOST} ^/support/ [NC]
RewriteRule ^(.*)$ [sheds-support.leisurebuildings.com$1...] [L,R=301]

but can't get either to work. Is the way I'm doing it a problem and how would I find out if there was a problem. Thanks.

# THIS REDIRECT LINKS SUPPORT BOARD TO NEW LOCATION
RedirectMatch 301 ^/support/(.*)$ [sheds-support.leisurebuildings.com...]

g1smd

3:49 pm on Jan 16, 2012 (gmt 0)

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



Use example.com in this forum to prevent URL auto-linking. You don't want Google making requests for /$1 on your site.

HTTP_HOST can test only the host name, no more, no less. It does not test protocol. It does not test path. Those elements must not be in your RegEx pattern.

Literal periods in your RegEx pattern must be escaped.

lucy24

5:32 pm on Jan 16, 2012 (gmt 0)

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



In English: HTTP_HOST is the part that begins in www and ends in dot com, as in

www.example.com

Or, ahem, that begins in not-www, if you prefer that form, and ends in dot org or dot net et cetera.

No slashes, but anchor at both ends.

robinantill

7:05 pm on Jan 16, 2012 (gmt 0)

10+ Year Member



Thank you both for your help, really appreciated. I will try to get my head around your suggestions.