force link with www

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

force link with www

Post by hongco »

how do we redirect any link to include www.
for instance, if a visitor type on the browser address: mydomain.com, mydomain.com/forums/
it will automatically redirect to http://www.mydomain.com and http://www.mydomain.com/forums, respectively?

would the mod rewrite work? and how?

Thanks! :wink:
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

hmm, I do not know why you would need to do this.. but I guess that is not the point..

If it does go to your page, you could have a small script on the index that would look something like this

Code: Select all

// $path = the location typed into the address bar

if($path != &quote;http://www.domain.com&quote;){
header(&quote;Location: http://www.domain.com&quote;); }
if($path != &quote;http://www.domain.com/forums&quote;) {
header(&quote;Location: http://www.domain.com/forums&quote;); }
Not sure if that will help, but I tried my best :D
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

i've got the solution

Code: Select all

RewriteEngine On
RewriteCond %{HTTP_HOST} =domain.com їNC]
RewriteRule ^ http://www.domain.com%{REQUEST_URI} їR,L]
ps: weird: i posted letter R comma L but it showed up are, L :)

Jcart | Its because its our aolbonics filter. Please post your code with

Code: Select all

or

Code: Select all

tags to avoid this filter.[/color]
Post Reply