forcing specific url to be displayed?

Using a single web hosting account to host multiple sites

forcing specific url to be displayed?

Postby code » Sun Apr 08, 2007 10:39 am

Code: Select all
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} (.*)three....
RewriteCond %{REQUEST_URI} !home/
RewriteRule ^(.*)$ home/$1 [R,L]


#removes leading www. from main url
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^onetwo\.net
RewriteRule (.*) http://onetwo.net/$1 [R,L]


I have onetwo.net on my hosting root with a test page for a second small site i want to build residing in onetwo.net/home

I have several domains for the second site:

onetwothree.com
onetwothree.net
onetwothree.org
three.net

using the above code, all incoming requests for the last 4 domains how load the test index page in onetwo.net/home

the next part of what I am trying to do is: for any content in /home, the browser should display http://one.two.three.net in the address bar, without showing any trailing folder or file name..

for example, at the moment:

three.net -loads-> onetwo.net/home -but displays-> http://onetwo.net/home
onetwothree.com -loads-> onetwo.net/home -but displays-> http://onetwo.net/home
onetwothree.net -loads-> onetwo.net/home -but displays-> http://onetwo.net/home
onetwothree.org -loads-> onetwo.net/home -but displays-> http://onetwo.net/home
one.two.three.net -loads-> onetwo.net/home -but displays-> http://onetwo.net/home

what i want to happen is:

three.net -loads-> onetwo.net/home -but displays-> http://one.two.three.net
onetwothree.com -loads-> onetwo.net/home -but displays-> http://one.two.three.net
onetwothree.net -loads-> onetwo.net/home -but displays-> http://one.two.three.net
onetwothree.org -loads-> onetwo.net/home -but displays-> http://one.two.three.net
one.two.three.net -loads-> onetwo.net/home -but displays-> http://one.two.three.net

also, the address for anything on the one.two.three.net domain (and therefore within /home) shouldnt show the trailing folder name, or file name (if thats even possible?), for example:

one.two.three.net/whatever.html -loads-> onetwo.net/home/whatever.html -but displays-> http://one.two.three.net
one.two.three.net/subfolder -loads-> onetwo.net/home/subfolder -but displays-> http://one.two.three.net

at the moment, I think I am coming up against problems due to the similarities within each domain name and it is causing constant loops whenever i try to force one.two.three.net to show because my expression is "(.*)three....".

Its taken about 2 weeks of messing with it to get this far, but i think im trying to do something that far exceeds my knowledge of mod_rewrite.. so any help would be greatly appreciated.

TIA.
code
 
Posts: 6
Joined: Sun Apr 08, 2007 9:35 am

Postby richardk » Sun Apr 08, 2007 12:21 pm

the address for anything on the one.two.three.net domain (and therefore within /home) shouldnt show the trailing folder name, or file name (if thats even possible?),

Only with a frame, and it's a bad idea.

Try this
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Remove www. from the main domain.
RewriteCond %{HTTP_HOST} ^www\.(onetwo\.net)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# Redirect all *three domains to one.two.three.net
RewriteCond %{HTTP_HOST} ^(www\.)?(onetwothree\.com|onetwothree\.net|onetwothree\.org|three\.net)$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.one\.two\.three\.net$ [NC]
RewriteRule ^(.*)$ http://one.two.three.net/$1 [R=301,L]

# Rewrite one.two.three.net to /home
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^one\.two\.three\.net$ [NC]
RewriteRule ^(.*)$ /home/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby code » Sun Apr 08, 2007 12:42 pm

That is absolutely fantastic.. only took a minor tweak to make it do everything i wanted..

thankyou so much. :D
code
 
Posts: 6
Joined: Sun Apr 08, 2007 9:35 am

Postby code » Thu Sep 06, 2007 6:05 am

Hi again.

Trying to add another domain to a new folder. Unfortunately simply duplicating the second part of the code you provided previously at the end doesnt seem to work.

Moved Permanently
The document has moved here.

Apache/1.3.33 Server at domain2.co.uk Port 80

I presume since it works perfectly on one domain/directory but not the other (even with the extra code), there is a fairly simple solution.. Sadly I have tried a few things and they generally lead to something breaking.
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Remove www. from the main domain.
RewriteCond %{HTTP_HOST} ^www\.(onetwo\.net)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# Redirect all *three domains to one.two.three.net
RewriteCond %{HTTP_HOST} ^(www\.)?(onetwothree\.com|onetwothree\.net|onetwothree\.org|three\.net)$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.one\.two\.three\.net$ [NC]
RewriteRule ^(.*)$ http://one.two.three.net/$1 [R=301,L]

# Rewrite one.two.three.net to /home
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^one\.two\.three\.net$ [NC]
RewriteRule ^(.*)$ /home/$1 [QSA,L]

# Redirect all domains to domain2.co.uk
RewriteCond %{HTTP_HOST} ^(www\.)?(domain2\.com|domain2\.net|domain2\.org|domain2\.co\.uk)$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.domain2\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://domain2.co.uk/$1 [R=301,L]

# Rewrite domain2.co.uk to /domain2
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^domain2\.co\.uk$ [NC]
RewriteRule ^(.*)$ /domain2/$1 [QSA,L]
any light anyone can shed on this would be hugely appreciated.

:)
code
 
Posts: 6
Joined: Sun Apr 08, 2007 9:35 am

Postby richardk » Thu Sep 06, 2007 2:46 pm

Try replacing
Code: Select all
^(www\.)?(domain2\.com|domain2\.net|domain2\.org|domain2\.co\.uk)$

with
Code: Select all
^(www\.)?domain2\.(com|net|org)$
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby code » Fri Sep 07, 2007 3:46 am

replaced
Code: Select all
^(www\.)?(domain2\.com|domain2\.net|domain2\.org|domain2\.co\.uk)$

with
Code: Select all
^(www\.)?domain2\.(com|net|org|co\.uk)$


but it still results in a 301 in opera :-?

firefox says its a loop
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.


everything else above that still works fine though. :o
code
 
Posts: 6
Joined: Sun Apr 08, 2007 9:35 am

Postby richardk » Sat Sep 08, 2007 7:46 am

Code: Select all
^(www\.)?domain2\.(com|net|org)$

It should not include .co.uk. The line below takes care of removing the www. from www.domain2.co.uk and by redirecting domain2.co.uk to domain2.co.uk your are causing a loop.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby code » Sat Sep 08, 2007 7:53 am

oops.. lol

and thanks again.
code
 
Posts: 6
Joined: Sun Apr 08, 2007 9:35 am

Postby code » Fri Sep 21, 2007 2:17 pm

found a bit of a glitch.

if i direct somone to domain2.co.uk/dir

it returns
The requested URL /domain2/domain2/dir/ was not found on this server.


but if i direct them to domain2.co.uk/dir/ with a trailing slash it loads.

:-?
code
 
Posts: 6
Joined: Sun Apr 08, 2007 9:35 am

Postby richardk » Fri Sep 21, 2007 2:27 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Remove www. from the main domain.
RewriteCond %{HTTP_HOST} ^www\.(onetwo\.net)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# Redirect all *three domains to one.two.three.net
RewriteCond %{HTTP_HOST} ^(www\.)?(onetwothree\.com|onetwothree\.net|onetwothree\.org|three\.net)$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.one\.two\.three\.net$ [NC]
RewriteRule ^(.*)$ http://one.two.three.net/$1 [R=301,L]

# Fix missing trailing slahses.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^one\.two\.three\.net$ [NC]
RewriteCond %{DOCUMENT_ROOT}/home%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [QSA,L]

# Rewrite one.two.three.net to /home
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^one\.two\.three\.net$ [NC]
RewriteRule ^(.*)$ /home/$1 [QSA,L]

# Redirect all domains to domain2.co.uk
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.(com|net|org)$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.domain2\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://domain2.co.uk/$1 [R=301,L]

# Fix missing trailing slahses.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^domain2\.co\.uk$ [NC]
RewriteCond %{DOCUMENT_ROOT}/domain2%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [QSA,L]

# Rewrite domain2.co.uk to /domain2
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^domain2\.co\.uk$ [NC]
RewriteRule ^(.*)$ /domain2/$1 [QSA,L]
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 8 guests

cron