Web Hosting Talk







View Full Version : Two really quick and simple questions I need help with


Hostex Australia
12-13-2005, 01:01 PM
Hey guys, thanks for helping. Here are my two questions:

1. I need to force WWW on the users of my site. So for example, if someone visits my site by going to domain.com I want it to redirect them to www.domain.com. I don't want to use any sloppy scripts or meta tags.

I dont think redirect permenant domain.com www.domain.com works

2. People are accessing my site by visiting the IP. I dont want this to happen. I would like people to be redirected to the domain if they type in the IP.

Thanks, if you know how to do either of the above, please dont leave this thread without telling me first :P

Dark Light
12-13-2005, 01:17 PM
Hello,

On the index page of your web site, you could get the HTTP_HOST that the user is viewing.

Check this against where you want them to go, such as www[dot]domain[dot]com (please replace '[dot]' with '.', as I can't post 'links'.), and if they don't match, redirect them using headers or similar redirection methods.

This should work for your IP too.

I hope this is want you want, else I apoligise,
Thanks,
Dark Light.

Hostex Australia
12-13-2005, 01:58 PM
Thanks Dark Light, that is what I want, but I think there are ways of doing it without touching the site files. But still, if all else fails I can try that :)

Burhan
12-14-2005, 04:01 AM
Answer to 1:


RewriteEngine on
RewriteCond %{HTTP_HOST} !^www
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [L,R]


Stick that in your .htaccess file

2. I'm not sure if this is possible (although I know of a way it can be done). However, this is a very bad idea. Why do you want to enforce this? If your DNS servers are down, then people can still access your site using the IP address. However, if you implement this 'feature', then your site will be unavailable even if the web server is running.