views:

83

answers:

2

Hi,

I want to redirect a url abc.xyz.com/123 to xyz.com. So the file that will be accessed will be index.php of xyz.com. That index.php should have available to it both abc and 123 (so 123 will be $_SERVER['PHP_SELF'], and abc will come out of $_SERVER['HTTP_HOST']) to enable appropriate processing.

abc.xyz.com already goes to xyz.com (though configuration by my service provider), and abc can be extracted out of $_SERVER['HTTP_HOST']. However, abc.xyz.com/123 seems to be looking for a folder called 123 in the root directory of xyz.com, and is showing up a 404 error when it cannot find any.

Can someone kindly give me the line(s) to be put in .htaccess to enable abc.xyz.com/123 to call index.php of xyz.com (with 123 being available though $_SERVER['PHP_SELF']? I cannot seem to get it to work.

Thank you very much for your time!

A: 

Perhaps something like:

RewriteEngine On
RewriteCond %{HTTP_HOST} .xyz.com  [NC]
RewriteRule ^(.*)$ index.php?param=$1 [L,QSA]

So, basically, if the HTTP host contains .xyz.com, (the presence of the dot at the front makes sure it only happens for subdomains) then everything is sent to index.php with whatever is after the domain attached as $_GET['param'].

Kazar
A: 

Thanks, Kazar, for the suggestion. I found the solution for my subdomain subdirectory redirection problem above, here it is:

Options +FollowSymLinks RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URL} !=/favicon.ico RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

knkk