SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2012
    Location
    US
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Advice needed on rewrites

    I have a client who has multiple domains, some are being indexed with AND without the www. The other issue is that they are all the same site. One of them has a different homepage, but all the content is running from the same server files. They also have two two folders, NEW folder and SERVICE AREAS folder, with identical files. This is causing an issue with their seo guy and the person who made the site for them doesn't know how to fix it! So the seo guy asked me to just rewrite all the domains to the main one with www. So my plan of attack is this:
    1) Make two redirects for each domain, one redirecting the non-www and one redirecting the www, to the main domain with the www
    2) Redirect the NEW folder to the Service Ares folder.

    My questions are:
    - do I have to write separate redirects for each domain twice, or is there a all inclusive way to do this?
    - can i redirect a folder? Like say mydomain.com/newfolder to mydomain.com/service-areas? Or would I have to redirect every page within the folder?
    - and lastly, would these folder or individual page redirects need to be done for each of the four domains?
    Thanks, Scott

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,895
    Mentioned
    138 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by satori83 View Post
    - do I have to write separate redirects for each domain twice, or is there a all inclusive way to do this?
    You can do this in one go. Either just redirect everything that is not the domain you want to the primary domain, or by using www as an optional atom

    Code:
    # pre-requisites for mod_rewrite
    # needed for both methods
    Options +FollowSymlinks
    RewriteEngine on
    
    # Method 1: REWRITE *ALL* THE THINGS! 
    RewriteCond %{HTTP_HOST} !^www\.primarydomain\.com$ [NC]
    RewriteRule .? http://www.primarydomain.com%{REQUEST_URI} [L,R=301]
    
    # Method 2: Optional www
    RewriteCond %{HTTP_HOST} !^(www\.)?some-secondary-domain\.com$ [NC]
    RewriteRule .? http://www.primarydomain.com%{REQUEST_URI} [L,R=301]
    Don't use both methods at once. Pick one and stick with it.

    Quote Originally Posted by satori83 View Post
    - can i redirect a folder? Like say mydomain.com/newfolder to mydomain.com/service-areas? Or would I have to redirect every page within the folder?
    Yes you can redirect a folder. The easiest way is to use

    Code:
    Redirect /newfolder http://www.primary-domain.com/service-areas
    Quote Originally Posted by satori83 View Post
    - and lastly, would these folder or individual page redirects need to be done for each of the four domains?
    That depends on how it's set up. If all domains are served from one directory you can apply method 1 from answer 1 just once. If they run from multiple directories you need to it apply it once for every directory.

    Also, I would put the redirect before the other Rewrite, because otherwise you'd have to redirect twice, once to the correct domain, and then once to the correct directory. Whereas if you put it first it redirects to the correct domain and folder at the same time.
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2012
    Location
    US
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok thanks. So if I understand correctly.... if I want all these selectwaterproofingnj.com, theoriginalselectbasementwaterproofing.com, betterhomesandbasements.com (both www and non www) to go to main domain of www.selectwaterproofingusa.com AND forward that folder, my code would be like this:

    Options +FollowSymlinks
    RewriteEngine on

    Redirect /newfolder http://www.selectwaterproofingusa.com/service-areas

    RewriteCond %{HTTP_HOST} !^www\.selectwaterproofingusa\.com$ [NC]
    RewriteRule .? http://www.selectwaterproofingusa.com%{REQUEST_URI} [L,R=301]

    How does Apache know to redirect those other domains since they aren't mentioned in the code?

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    satori83,

    Apache doesn't have to know as you've indicated the files are co-located (parked domains). Therefore, there's only one .htaccess to work with so Apache will do it all there. If they're not co-located, just do the same thing in each DocumentRoot.

    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


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
  •