Web Hosting Talk







View Full Version : mod_rewrite - Redirect every URL... (Whois.sc redirection)


CreativeLogic
11-01-2005, 04:07 PM
I need some help with a mod_write problem. I'm trying to do exactly what www.whois.sc does with the domains at the end like this:
http://www.whois.sc/webhostingtalk.com

Any and all domain in the form of that or any other type of forms like:
http://www.webhostingtalk.com
http://webhostingtalk.com
www.webhostingtalk.com
webhostingtalk.com
http://www.webhostingtalk.com/
http://webhostingtalk.com/
www.webhostingtalk.com/
webhostingtalk.com/

They all need to be redirected to one file, let's say domain.php?domain=DOMAIN_HERE.

Can anyone help me figure this out?

I'm paying $10 to the first person who posts an htaccess fix for this.

CreativeLogic
11-01-2005, 05:01 PM
Code recieved on another forum.

WO-Jacob
11-01-2005, 05:02 PM
I need some help with a mod_write problem. I'm trying to do exactly what www.whois.sc does with the domains at the end like this:
http://www.whois.sc/webhostingtalk.com

Any and all domain in the form of that or any other type of forms like:
http://www.webhostingtalk.com
http://webhostingtalk.com
www.webhostingtalk.com
webhostingtalk.com
http://www.webhostingtalk.com/
http://webhostingtalk.com/
www.webhostingtalk.com/
webhostingtalk.com/

They all need to be redirected to one file, let's say domain.php?domain=DOMAIN_HERE.

Can anyone help me figure this out?

I'm paying $10 to the first person who posts an htaccess fix for this.

RewriteEngine On
RewriteRule ^(.*)\.php$ $1.php [L]
RewriteRule ^(.*)$ file.php?DOMAIN=$1

I believe should work for ya, though YMMV ;)

CreativeLogic
11-01-2005, 05:04 PM
That's the code I had before and it didn't work all the time. Sometimes it would give a 404 error.

WO-Jacob
11-01-2005, 05:13 PM
The exact code? hum. Only way I can see it would cause issues is if they put in http://www.somesite.com/index.php or whatever, which it isn't really meant for anyway... probably just need to add a RewriteCond on SCRIPT_FILENAME... like

RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ file.php?DOMAIN=$1 [L]

}T{Reme [Q_G]
11-01-2005, 05:16 PM
Mod_rewrite allows regex so that's reasonably easy. Something like this should work

RewriteRule ^((http:\/\/)?(www)?\.?(.+?)(\.[a-z]{3,4})\/?)$ domain.php?domain=$4$5

$1 contain the entire entry http://www.somesite.com/
$2 contain http:// (if entered)
$3 contains www (if entered)
$4 contains somesite
$5 contains .com

CreativeLogic
11-01-2005, 05:31 PM
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ info.php?domain=$1 [L]

That's the code I'm using...