/    Sign up×
Community /Pin to ProfileBookmark

.htacess help needed

OK, we need a little help with some domain redirects from some experts please. I’ll post the code we have currently in the .htaccess file a little further down, but I’ll explain what we are trying to achieve:

  • 1. primary domain (primary.com in code below), should always use www prefix

  • 2. primary domain should always use /en/ as the main “home” page

  • 3. any parked domains on this account should redirect to primary domain
  • What we have below actually works and does everything we asked for above, however what we now want to do is redirect a few parked domains (not “all” parked domains) to specific urls, whilst leaving any others that are not specifically redirected continuing to redirect to the primary domain.

    So, for example, if visitor accesses “parkedomain1.com” (with or without www), they would be redirected to “http://www.primary.com/category/page-01.php

    Or, if visitor accesses “parkedomain2.com” (with or without www), they would be redirected to “http://www.primary.com/category/page-02.php

    But if visitor accesses “any” other parked domain, they’d continue to be redirected to the primary domain (a catchall as it were).

    We’re trying to make the .htaccess file as small as possible, and without having to specifically list “all” parked domains with specific redirects as it makes the file too large, we’d like to find a solution where we explicitly list the parked domains we want to redirect to specific urls only, and have a catchall for anything else not specifically listed.

    Hope that makes sense, and hope you can help! ?

    Here’s the code we’re using currently:


    ————————————-

    # Always use www in the domain

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^([a-z.]+)?primary.com$ [NC]
    RewriteCond %{HTTP_HOST} !^www. [NC]
    RewriteRule .? http://www.%1primary.com%{REQUEST_URI} [R=301]

    # Always use www in the domain

    # redirect ANY other domain that doesn’t match www.primary.com to main domain

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www.primary.com [NC]
    RewriteRule ^(.*)$ http://www.primary.com/$1 [R=301]

    # redirect ANY other domain that doesn’t match www.primary.com to main domain

    # Set a default home directory, (this subfolder always loads)

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^$ /en/ [R=301]
    </IfModule>

    # Set a default home directory, (this subfolder always loads)

    # disable ETags #

    Header unset ETag
    FileETag None

    # disable ETags #

    # BEGIN add gZip compression

    <IfModule deflate_module>
    <IfModule filter_module>
    AddOutputFilterByType DEFLATE text/plain text/html
    AddOutputFilterByType DEFLATE text/xml application/xml application/xhtml+xml application/xml-dtd
    AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml image/svg+xml
    AddOutputFilterByType DEFLATE text/css text/javascript application/javascript application/x-javascript
    AddOutputFilterByType DEFLATE font/otf font/opentype application/font-otf application/x-font-otf
    AddOutputFilterByType DEFLATE font/ttf font/truetype application/font-ttf application/x-font-ttf
    </IfModule>
    </IfModule>

    # END add gZip compression

    ## EXPIRES CACHING ##

    <IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg “access plus 1 year”
    ExpiresByType image/jpeg “access plus 1 year”
    ExpiresByType image/gif “access plus 1 year”
    ExpiresByType image/png “access plus 1 year”
    ExpiresByType text/css “access plus 1 month”
    ExpiresByType application/pdf “access plus 1 month”
    ExpiresByType text/x-javascript “access plus 1 month”
    ExpiresByType application/x-shockwave-flash “access plus 1 month”
    ExpiresByType image/x-icon “access plus 1 year”
    ExpiresDefault “access plus 2 days”
    </IfModule>

    ## EXPIRES CACHING ##

    ### BEGIN TIMEZONE

    SetEnv TZ Asia/Bangkok

    ### END TIMEZONE

    # BEGIN WordPress

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress


    ————————————-

    to post a comment
    HTML

    0Be the first to comment 😎

    ×

    Success!

    Help @CMYKreative spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.20,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...