SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Domains and htaccess

    We have domains like site.co.uk, website.co.uk, 777.co.uk, online24.org.uk, etc.

    All these domains refer to only once directory (virtual hosting). It's OK.


    Names of files for these domains looks like

    sitecouk.html sitecouk2.html sitecouk3.html ...
    websitecouk.html websitecouk2.html websitecouk3.html ...
    777couk.html 777couk2.html 777couk3.html ...
    online24orguk.html online24orguk2.html online24orguk2.html ...

    The name of the first file may look and like sitecouk1.html too. It is easy to change it from sitecouk.html


    How to write only some strings in .htaccess file which will rightly show requested files of all these domains if it is possible?


    Examples of requests and redirections:

    http://www.site.co.uk -> sitecouk1.html
    http://www.site.co.uk/site1.html -> sitecouk1.html
    http://www.site.co.uk/site2.html -> sitecouk2.html
    ...

    http://www.website.co.uk -> websitecouk1.html
    http://www.website.co.uk/website1.html -> websitecouk1.html
    http://www.website.co.uk/website2.html -> websitecouk2.html
    ...




    Thanks in advance.

  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)
    Di,

    That's easy!
    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} (site|website|777online24)\.co\.uk
    RewriteRule ([0-9]+\.html) %1couk$1 [L]
    The way I resolve this "problem" on my "parked" websites is with PHP code which makes changes to the displayed code using $_SERVER['HTTP_HOST'] so each script needs only be created once.

    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
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, dklynn. It's really easy.


    This is the first part of my variant before I read your one:
    RewriteCond %{HTTP_HOST} (www\.)?([a-z0-9-]+)\.co\.uk [NC]
    RewriteRule ^([a-z0-9-]+)([0-9]+)\.html$ $1couk$2.html [L,NC,QSA]

    And as I understand we should also add for the first string http://www.site.co.uk -> sitecouk1.html something like that

    RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
    RewriteRule ^(www\.)?([a-z0-9-]+)\.co\.uk(.*) $2couk1.html [L,NC,QSA]


    After reading yours I see what I can change now. I will glad for more advices.

  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)
    Hi Di!

    The trick was to only capture the domain name without the extensions.

    Because you cannot examine the {HTTP_HOST} variable with a RewriteRule, your second rule cannot possibly work - nor the first.

    Please have a read of the tutorial article linked in my signature.

    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
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think that it is not necessary to write NC more than once if we already did it in RewriteCond.. Right?

    I have read your article. May you write the example of web-address when it will not work? Thanks.

  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)
    Di,

    The NC in the RewriteCond statement is because the {HTTP_HOST} is case insensitive. If you can accept any mix in the RewriteRule, NC's okay there, too, but NOT advisable.

    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
  •