Htaccess / regex / php I dont know why it won't work
| From: | affixcom | Date: | Tue, 02 Oct 2001 18:53:32 +0000 |
| Subject: | Htaccess / regex / php I dont know why it won't work | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-69619@lists.php.net to get a copy of this message | ||
Hi,
I have a website hosted on a cobalt server with my own domain, but not my own IP.
I have a full access to my root web, but not higher (means can't change any *.conf files).
My domain is "wildcarded"
I want to be able to redirect based on the entry, IE
if a user types http://hello.mydomain.com he will go to http://mydomain.com/hello=20
if a user types http://another.mydomain.com he will go to
http://mydomain.com/another=20
The redirect method of apache doesn't work because I leanred that that is based on an absolute
path from the server
I tried php scripts that read the subdomain and use it in the header function but it won't
work.
I came to the conclusion after a lot of tests that rewriterule from the htaccess is the the best.
htaccess script: (doesn't work)
RewriteEngine On
RewriteRule ^(.*)\.zajfe\.org$ redirect.php?url=$1 [L]
connected to the page redirect.php where
<?header("location:http://www.zajfe.org/$url");?>
PHP script: (doesn't work)
<?
$domain = "yourdomain.com";
$default_page = "main.shtml";
$underdomaene = $HTTP_HOST;
$underdomaene = eregi_replace("\.".$domain, "", $underdomaene);
$underdomaene = eregi_replace("www\.", "", $underdomaene);
$underdomaene = strtolower($underdomaene);
if (is_dir("$DOCUMENT_ROOT/$underdomaene")) {
header("Location: http://$domain/$underdomaene");
}
else {
if (!$REQUEST_URI || $REQUEST_URI == "/") {
include("$DOCUMENT_ROOT/$default_page");
}
else {
header("Location: http://$domain$REQUEST_URI");
}
}
?>
I am open to ANY suggestion, CGI / ASP / PHP / SSI (it is all on the server), I want it to work
Thanks
Gab