Main domain/Add-on Domain conflicting redirect rules

Following on from this thread, I’ve moved one of my domains and am now hosting it as an add-on domain on another account. This puts it in a sub-directory e.g. maindomain.co.uk/addondomain.co.uk, so it can be accessed via two URLs. (Three, according to [URL=“http://www.sitepoint.com/forums/showthread.php?824291-Hosting-multiple-sites-via-cPanel&p=5048420&viewfull=1#post5048420”]ldcdc, but I can’t find a third version that works.)

I’m trying to redirect maindomain.co.uk/addondomain.co.uk to www.addondomain.co.uk, but I’ve run into a snag.

I have this in my .htaccess for maindomain.co.uk:

Redirect 301 /addondomain.co.uk/ http://www.addondomain.co.uk/

which works for most pages.

Unfortunately, I also have

Redirect 301 /index.html /index.php
Redirect 301 /contact.html /contact.php

which is causing 404 errors on index.html and contact.html in the add-on domain.

I’ve tried changing the order of the two redirect sections, but it doesn’t help. I’ve also tried adding

Redirect 301 /addondomain.co.uk/index.html http://www.addondomain.co.uk/index.html
Redirect 301 /addondomain.co.uk/contact.html http://www.addondomain.co.uk/contact.html

but that doesn’t work, either.

Where am I going wrong? Is there a better way to do this?

tb,

With deference to Dan, I believe that you only have two ways to get to your addon domain which are as you’ve indicated.

Redirect 301 /addondomain.co.uk/ http://www.addondomain.co.uk/

I’m SHOCKED! Is the addon domain’s directory addondomain.co.uk?

Oh, well, that should also maintain the {REQUEST_URI} of the original request which is probably not what you want, ergo, I’d fall back on mod_rewrite as follows:

RewriteEngine on
RewriteRule ^{addon_domain_subdirectory}/(.*)$ http://www.addondomain.co.uk/$1 [R=301,L]

As for your redirects, they should work perfectly in the maindomain. The absolute /index.html should restrain that Redirect to the DocumentRoot (of maindomain). Ditto contact.html. If they don’t, continue your mod_rewrite code with:

RewriteRule ^(index|contact)\\.html$ $1.php [R=301,L]

The power of regular expressions can normally overcome irregularities like you’re having with mod_alias.

Regards,

DK

Thanks for the reply.

Yes. That was the default, and as I’ve never done this before, I didn’t try to change it because I assumed it wouldn’t work if I did.

I’ve tried that, and it isn’t redirecting the subdomain at all. I have it as

RewriteRule ^{addondomain.co.uk}/(.*)$ http://www.addondomain.co.uk/$1 [R=301,L]

which I think is correct. It makes no odds whether I put it before or after the redirects. Where have I screwed up?

tb,

You’re doing it corretly, therefore, there must be something wrong with the server, i.e., mod_rewrite is not enabled. Have you run the test in my signature’s tutorial (or verified via any other means)? Okay, the easiest way to test that .htaccess is the file being read and parsed is to add foobah as a directive and look for Error 500 (then remove foobah, obviously). On the other hand, if you do not get a 500, then your .htaccess is a red herring … contact your host to find out what the file is that will allow you to use mod_rewrite.

Regards,

DK

Thanks DK. I should have mentioned that I know mod_rewrite is enabled, because the main domain is set to rewrite domain.co.uk to www.domain.co.uk, and that’s always worked. (I also tried commenting out those lines to see if that might be causing a problem, but it still doesn’t work.)

TB,

Working? Then there is a conflict which can only be spotted if the whole mod_rewrite part of the .htaccess file is provided (by PM, if necessary).

Regards,

DK

Hi DK,

I’ve tried commenting out other rewrite rules, but without success. I finally cut out all of the rewrite rules apart from the ones mentioned above and I still can’t get it to work. I’ll PM you a copy of the actual .htaccess file, in case I’ve made some daft typo or something in the “real thing” that isn’t in my “censored” version above.

I’ve tried it on three different browsers, and cleared the caches on all of them, so I don’t think it’s simply a caching issue.

Thanks.

TB