Two domains, two index files, everything else the same

Using a single web hosting account to host multiple sites

Two domains, two index files, everything else the same

Postby pjc007 » Tue Jan 20, 2009 1:05 pm

Hi,

my hosting provider pointed me at mod_rewrite for this problem, but while I *am* a programmer, I'm kinda lost with all the documentation at the moment.

Here's what I'd like to do:

Request: http://www.x.com -> index_com.html
Request: http://www.x.co.uk -> index_co_uk.html

Any other requests go to all the same files.

[Edit - both domains are set up to point to exactly the same directory on the hosting service]

Basically this is a marketing thing - I would like to have different content (and, more importantly meta-tags) for users who use the uk domain to those that use the global one.

I'm sure this is easy to do, and if it's already been answered, please point me there.

I have searched, but must be asking the wrong search questions.

Thanks in advance.

PJC
pjc007
 
Posts: 2
Joined: Tue Jan 20, 2009 1:00 pm

Postby richardk » Tue Jan 20, 2009 1:17 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST}/index_com.html   ^(www\.)?example\.com(/index_com.html)$   [NC,OR]
RewriteCond %{HTTP_HOST}/index_co_uk.html ^(www\.)?example\.co\.uk(/index_co_uk.html)$ [NC]
RewriteRule ^$ %2 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby pjc007 » Tue Jan 20, 2009 1:37 pm

Many thanks - that appears to be working perfectly :)

Trying to improve my own knowledge here - I figured out the regexes in there, but what are the [] flags for?

Just wondering, already happy :)

-PJC
pjc007
 
Posts: 2
Joined: Tue Jan 20, 2009 1:00 pm

Postby richardk » Tue Jan 20, 2009 4:00 pm

QSA stands for Query string Append. So example.co.uk/?something will rewrite to /index_co_uk.html?something. You might not need this but it usually doesn't hurt.
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule wrote:'qsappend|QSA' (query string append)
This flag forces the rewrite engine to append a query string part of the substitution string to the existing string, instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule.


L stands for Last. It stops any more rules being processed that request. However, in .htaccess files and <Directory>s if a rewrite occurs back to the same directory (that contains this .htaccess file) it will be processed again because it is a sub request. This does not happen in the httpd.conf file or <VirtualHost>s.
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule wrote:'last|L' (last rule)
Stop the rewriting process here and don't apply any more rewrite rules. This corresponds to the Perl last command or the break command in C. Use this flag to prevent the currently rewritten URL from being rewritten further by following rules. Remember, however, that if the RewriteRule generates an internal redirect (which frequently occurs when rewriting in a per-directory context), this will reinject the request and will cause processing to be repeated starting from the first RewriteRule.


There is more information in the Apache mod_rewrite documentation.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 23 guests

cron