Rewrite problems

Using a single web hosting account to host multiple sites

Rewrite problems

Postby DanUK » Mon Dec 31, 2007 12:09 pm

Hi guys, happy new year.

I hope you can help me please

I have multiple sites hosted on a shared server, and although the following .htaccess works, it doesn't work perfectly.

The problem is that when something is refreshed with a meta refresh, I get http://domain1.com/www.domain1.net/foo.php whereas I don't want want the "/www.domain1.net" ... similaly, I can request another site from another, with for example: http://domain1.net/www.domain2.net will load domain2 (again, not good)

Any ideas?

Code: Select all
# Error handling

ErrorDocument 404 /404.php

# Blacklist

order allow,deny

deny from 61.6.192.
deny from 61.6.226.
deny from .bn
allow from all

# Rewrite engine

RewriteEngine on

RewriteCond %{HTTP_HOST} domain1\.net$ [NC]
RewriteRule ^(.*)$ /www.domain1.net/$1 [L]

RewriteCond %{HTTP_HOST} domain2\.net$ [NC]
RewriteRule ^(.*)$ /www.domain2.net/$1 [L]

RewriteCond %{HTTP_HOST} domain3\.net$ [NC]
RewriteRule ^(.*)$ /www.domain3.net/$1 [L]
DanUK
 
Posts: 7
Joined: Mon Dec 31, 2007 12:06 pm

Postby richardk » Mon Dec 31, 2007 2:49 pm

It's really a problem with the code creating the meta refresh.

This should redirect any requests that show the domain sub directory to the domain only.
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?(domain1\.net|domain2\.net|domain3\.net)$ [NC]
RewriteRule ^www\.(domain1\.net|domain2\.net|domain3\.net)(/(.*))?$ http://www.$1/$3 [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?(domain1\.net|domain2\.net|domain3\.net)$ [NC]
RewriteRule ^(.*)$ /www.%2/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby DanUK » Mon Dec 31, 2007 3:04 pm

Hi there
Thank you for your reply

I haven't tested that yet, but it's not the code for the meta refresh I don't think.

On a phpinfo I see:

Code: Select all
SCRIPT_FILENAME  /home/me/htdocs/www.domain1.net/phpinfo.php 
REDIRECT_URL  /www.domain1.net/phpinfo.php 
SCRIPT_NAME  /www.domain1.net/phpinfo.php 
ORIG_PATH_TRANSLATED  /home/me/htdocs/www.domain1.net/phpinfo.php 
ORIG_PATH_INFO  /www.domain1.net/phpinfo.php 

PHP_SELF  /www.domain1.net/phpinfo.php 


which makes me think it is something I've done with .htaccess

:)
DanUK
 
Posts: 7
Joined: Mon Dec 31, 2007 12:06 pm

Postby richardk » Mon Dec 31, 2007 3:47 pm

Mod_rewrite doesn't (can't) change any of those variables (it does add REDIRECT_* variables, though) so you have to change the meta refresh code to work with mod_rewrite (like you have to edit the links in pages).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby DanUK » Mon Dec 31, 2007 6:17 pm

Hi there
I gave that a try

Code: Select all
Not Found

The requested URL /www./index.php was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


it worked again if I tried http://us.net/www.domain1.net/foo - weird :(

Thanks for your help though, I really appreciate it
DanUK
 
Posts: 7
Joined: Mon Dec 31, 2007 12:06 pm

Postby richardk » Tue Jan 01, 2008 5:33 pm

What URL did you go to that produced the 404? (If it was the meta refresh, what was the meta refresh's URL.)

it worked again if I tried us.net/www.domain1.net/foo - weird

What do you mean by worked? It showed the wrong content as it did before? It redirected to the correct URL?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby DanUK » Sat Jan 05, 2008 10:55 am

Hi, thanks for your response
Happy new year

The 404 was generated by my index.php (which is there, as soon as I reverted back to the old .htaccess it worked ok)

By "it worked again if I tried us.net/www.domain1.net/foo - weird" i mean that if I requested another site by http://us.net/domain2.net it still brought up the other site, so it didn't fix that

Weird!
DanUK
 
Posts: 7
Joined: Mon Dec 31, 2007 12:06 pm

Postby richardk » Sat Jan 05, 2008 11:14 am

If you put the following in your .htaccess file (just this) and go to domain2.com do you get rewritten to /www.domain2.com?
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?(domain1\.net|domain2\.net|domain3\.net)$ [NC]
RewriteRule ^(.*)$ /www.%2/$1 [QSA,L]


Then, if you put the following in your .htaccess file (just this) and go to us.net/www.domain2.com/a do you get redircted to http://www.domain2.com/a?
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?(domain1\.net|domain2\.net|domain3\.net)$ [NC]
RewriteRule ^(www\.)?(domain1\.net|domain2\.net|domain3\.net)(/(.*))?$ http://www.$2/$4 [R=301,L]


Then try them together
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?(domain1\.net|domain2\.net|domain3\.net)$ [NC]
RewriteRule ^(www\.)?(domain1\.net|domain2\.net|domain3\.net)(/(.*))?$ http://www.$2/$4 [R=301,L]

RewriteCond %{HTTP_HOST} ^(www\.)?(domain1\.net|domain2\.net|domain3\.net)$ [NC]
RewriteRule ^(.*)$ /www.%2/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby DanUK » Sat Jan 19, 2008 4:05 pm

Hi guys, i've still been trying to fix this with no luck

It most certainly isn't to do with metas in my opinion. When I try to request one of my sites that has nothing in it at all, I get this:

Code: Select all
Forbidden

You don't have permission to access /www.site2.co.uk/ on this server.


So trying to find an index.php wants to go to http://foo.com/www.site2.co.uk/index.php

Very annoying :S

Thanks for any help :)
DanUK
 
Posts: 7
Joined: Mon Dec 31, 2007 12:06 pm

Postby richardk » Sat Jan 19, 2008 4:52 pm

It most certainly isn't to do with metas in my opinion. When I try to request one of my sites that has nothing in it at all, I get this:

Metas? Then there must be some other mod_rewrite or other Apache configuration as this mod_rewrite only matched the domains in the RewriteCond.

Please answer these questions from my previous post.
Code: Select all
If you put the following in your .htaccess file (just this) and go to domain2.com do you get rewritten to /www.domain2.com?
...
Then, if you put the following in your .htaccess file (just this) and go to us.net/www.domain2.com/a do you get redircted to http://www.domain2.com/a?

(Although it should be .net.)
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 22 guests

cron