Forum Moderators: phranque

Message Too Old, No Replies

[Rewrite] multi domain

         

114v

11:14 am on May 1, 2007 (gmt 0)

10+ Year Member



I'm using:


RewriteEngine On
#
# Case 1: No subdomain, no resource name
# If domain is "domain.com" or "www.domain.com"
rewritecond %{http_host} ^(www\.)?domain\.com
# Rewrite blank request to script with no parameters
rewriterule ^$ /index.php? [L]
#
#Case 2: No subdomain with resource name
# Prevent rewrite loop if we've already rewritten to index.php
rewritecond %{REQUEST_URI}!^/index\.php$
# If domain is "domain.com" or "www.domain.com"
rewritecond %{http_host} ^(www\.)?domain\.com
# Rewrite to script with q parameter set to requested resource
rewriterule ^([^.]+)\.html$ /index.php?q=$1 [L]
#
# Case 3: subdomain with no resource name
# If subdomain is not (only) "www"
# Create a back-reference to required subdomain
rewritecond %{http_host} ^(www\.)?([^.]+)\.domain\.com
# Rewrite blank request to script with s parameter set to subdomain.
rewriterule ^$ /index.php?s=%2 [L]
#
# Case 4: subdomain with resource name
# Prevent a rewrite loop if we've already rewritten to index.php
rewritecond %{REQUEST_URI}!^/index\.php$
# If subdomain is not (only) "www"
# Create a back-reference to required subdomain
rewritecond %{http_host} ^(www\.)?([^.]+)\.domain\.com
# Rewrite to script with s parameter set to subdomain
# and q parameter set to requested resource.
rewriterule ^([^.]+)\.html$ /index.php?s=%2&q=$1 [L]

It only work for domain.com.
I need rewrite for another domain (multi domain).

Thank you very much

jd01

12:40 pm on May 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure I understand, but if you remove the HTTP_HOST conditions it should work for all domains and subs…

For SEO and non-duplicate content it is probably better to redirect all versions of domains and subs with the same content to a single version.

In other words:

Redirect all requests to www.example.com, then set your .htaccess to work with www.example.com, which it already appears to.

# Check for a host header to prevent looping of HTTP 1.0 clients.
RewriteCond %{HTTP_HOST} .
# Check to see if the visitor is already on www.
RewriteCond %{HTTP_HOST} ^www\.example\.com$
#Check all requests & Redirect to www. if the conditions match.
RewriteRule .? http://www.example.com/

You might also want to correct you capitalization:
RewriteRule
RewriteCond
%{VARIABLE_NAME}

But that's up to you if it's working correctly.

Justin