Forum Moderators: phranque

Message Too Old, No Replies

one site, two domains

how to configure the .htaccess file

         

Baze

12:00 pm on Nov 9, 2006 (gmt 0)

10+ Year Member



Hi guys,

i'm running blog hosting script which uses .htaccess file to create the subdomains for the users (user.domain.com)

recently i've purchased another domain name and point it to the same location as the first one.

what i want to get is to be able to access all blogs from both domain names (blog.domain1.com = blog.domain2.com)

the current .htacces file is the following:

RewriteEngine On
Options +Followsymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\. [NC]
RewriteCond %{REQUEST_FILENAME}!^.*/images/.*$
RewriteCond %{REQUEST_FILENAME}!^.*/uploads/.*$
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.domain1\.com(:80)?<>/([^/]*) [NC]
RewriteCond %1<>%3!^(.*)<>\1$ [NC]
RewriteRule ^(.*)$ - [E=BLOGUSER:%1]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^$ /index.php?w=%1 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^page([0-9]+)/([^/]+)?$ /index.php?w=%1&page=$1$2 [L]
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^profiles/([^/]+)/([^/]+)?$ /profile.php?u=$1$2 [L]
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^profiles/?$ /profile.php [L]
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^albums/([^/]+)/([^/]+)?$ /album.php?u=$1$2 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^archive/(.*)/(.*)/([^/]+)?$ /archive.php?w=%1&y=$1&m=$2$3 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^archive\.php/(.*)/(.*)/([^/]+)?$ /archive.php?w=%1&y=$1&m=$2$3 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^archive/(.*)/([^/]+)?$ /archive.php?w=%1&y=$1$2 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^archive\.php/(.*)/([^/]+)?$ /archive.php?w=%1&y=$1$2 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^archive/([^/]+)?$ /archive.php?w=%1$1 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^archive\.php/([^/]+)?$ /archive.php?w=%1$1 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^friends/([^/]+)?$ /friends.php?w=%1$1 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^friends\.php/([^/]+)?$ /friends.php?w=%1$1 [L]
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^([^/]+)/friends/page([0-9]+)/([^/]+)?$ /friends.php?w=$1&page=$2$3 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^([0-9]+)/([^/]+).html$ /entry.php?w=%1&e_id=$1 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^([0-9]+)/([^/]+)?$ /entry.php?w=%1&e_id=$1$2 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^&([^/]+)?$ /index.php?w=%1&$1 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^([^/]+)/([^/]+)?$ /index.php?w=%1&category=$1$2 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^([^/]+)/page([0-9]+)/([^/]+)?$ /index.php?w=%1&category=$1&page=$2$3 [L]

if i change
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.domain1\.com(:80)?<>/([^/]*) [NC]
into
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.domain2\.com(:80)?<>/([^/]*) [NC]

everything works fine only for the second domain (e.g. blogname.domain2.com)

if i leave both lines
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.domain1\.com(:80)?<>/([^/]*) [NC]
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.domain2\.com(:80)?<>/([^/]*) [NC]
the links don't work at all, they redirect to the portal page

is there a string or something which will tell the file to use both domains...something like
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.domain1\.com(:80),\.domain2\.com(:80)?<>/([^/]*) [NC]

i'm only thinking loudly, probably its nonsense...

anyway, i really want to make this work so any kind of help is appreciated

thanks,
Baze

jdMorgan

4:18 pm on Nov 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.domain1\.com(:80)?<>/([^/]*) [NC,[b]OR[/b]]
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.domain2\.com(:80)?<>/([^/]*) [NC]

or alternately:

RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.(domain1¦domain2)\.com(:80)?<>/([^/]*) [NC]

Notice: Replace the broken pipe "¦" character used above to specify an in-line OR with a solid pipe character from your keyboard before use; Posting on this forum modifies the pipe characters.

You could also use the in-line OR to reduce your per-page rules by half. Just a random example:


RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^archive/([^/]+)?$ /archive.php?w=%1$1 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^archive\.php/([^/]+)?$ /archive.php?w=%1$1 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^friends/([^/]+)?$ /friends.php?w=%1$1 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^friends\.php/([^/]+)?$ /friends.php?w=%1$1 [L]

can be reduced to:

RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^(archive¦friends)(\.php)?/([^/]+)?$ /$1.php?w=%1$3 [L]

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

Baze

5:23 pm on Nov 9, 2006 (gmt 0)

10+ Year Member



Hi Jim,

it works great! Thank you very much!

all the best,
Baze

pixeltierra

6:09 pm on Nov 9, 2006 (gmt 0)

10+ Year Member



If you rely on googel traffic, you might have duplicate content problems.