tags:

views:

62

answers:

2

Hello!

My .htaccess file has the following code:

RewriteEngine on
RewriteRule ^/?(.*)$ index.php?domain=$1 [L]

I'm trying to get domain names as variables from URLs like:

hxxp://www.example.com/www.domain.name or

hxxp://www.example.com/subdomain.domain.name or

hxxp://www.example.com/domain.name

but with $_GET['domain'] my variable is always 'index.php' and not the domain names.

With hxxp://www.example.com/domain/www.domain.name and .htaccess code

RewriteEngine on
RewriteRule ^domain/?(.*)$ index.php?url=$1 [L]

everything is OK, but I would like to remove the 'domain/' part from the URLs.

I've searched for this, but couldn't find anything. Could someone please help me with this?

A: 

something like

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?domain=$1 [L]

in this case $1 will be:

http://site/www.example.com        $1 = www.example.com
http://site/www.example.com/xyz    $1 = www.example.com/xyz
jspcal
Thank you! This works, but redirects as a non search engine friendly URL. I would like to leave the URLs as in my example.
digitron
k, if you remove the [R=302] it will do an internal redirect, preserving the neat url (edited above)
jspcal
thank you, this works perfectly!
digitron
A: 

Try this rule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^[^/.](\.[^/]+)+$ index.php?domain=$0 [L]

This will rewrite any request with a URL path that contains at least one dot (foo.bar, foo.bar.baz, etc.) to your index.php.

Gumbo
Thank you! The code you wrote did not work for me (404 Not Found error for a domain name entered after the forward slash). I'm pretty new to mod_rewrite, but I modified the last line to RewriteRule ^([^/]+)$ index.php?url=$1 [L] and this works, although I really do not know what it does.
digitron