SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Life is not a malfunction gold trophysilver trophybronze trophy
    TechnoBear's Avatar
    Join Date
    Jun 2011
    Location
    Argyll, Scotland
    Posts
    6,437
    Mentioned
    274 Post(s)
    Tagged
    5 Thread(s)

    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 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:
    Code:
    Redirect 301 /addondomain.co.uk/ http://www.addondomain.co.uk/
    which works for most pages.

    Unfortunately, I also have
    Code:
    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
    Code:
    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?

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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.

    Code:
    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:

    Code:
    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:

    Code:
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    Life is not a malfunction gold trophysilver trophybronze trophy
    TechnoBear's Avatar
    Join Date
    Jun 2011
    Location
    Argyll, Scotland
    Posts
    6,437
    Mentioned
    274 Post(s)
    Tagged
    5 Thread(s)
    Thanks for the reply.

    Quote Originally Posted by dklynn View Post
    tb,
    I'm SHOCKED! Is the addon domain's directory addondomain.co.uk?
    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.

    Quote Originally Posted by dklynn View Post
    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:

    Code:
    RewriteEngine on
    RewriteRule ^{addon_domain_subdirectory}/(.*)$ http://www.addondomain.co.uk/$1 [R=301,L]
    I've tried that, and it isn't redirecting the subdomain at all. I have it as
    Code:
    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?

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  5. #5
    Life is not a malfunction gold trophysilver trophybronze trophy
    TechnoBear's Avatar
    Join Date
    Jun 2011
    Location
    Argyll, Scotland
    Posts
    6,437
    Mentioned
    274 Post(s)
    Tagged
    5 Thread(s)
    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.)

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  7. #7
    Life is not a malfunction gold trophysilver trophybronze trophy
    TechnoBear's Avatar
    Join Date
    Jun 2011
    Location
    Argyll, Scotland
    Posts
    6,437
    Mentioned
    274 Post(s)
    Tagged
    5 Thread(s)
    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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •