How do you convert http://domain.com to http://www.domain.co

New to mod_rewrite? This is a good place to start.

Postby Abunai » Fri Jul 12, 2002 12:04 am

I was wondering how to convert http://domain.com to http://www.domain.com

and also add a backslash to the end of folders, for instance

http://coolbeans.com/folder turns into http://www.coolbeans.com/folder/

Any help is greatly appeciated,
btw I've read the apache docs on mod_rewrite and searched for mod_rewrite info on google, they did not help me for this situation.
Abunai
 
Posts: 1
Joined: Thu Jul 11, 2002 4:00 pm
Location: Alabama, USA

Postby Brett » Mon Aug 05, 2002 1:47 pm

If your server is not responding to http://domain.com (without www), that is a DNS error and not related to mod_rewrite.

On the other hand, if your server DOES respond to http://domain.com and you want to redirect to http://www.domain.com, you can do this:
Code: Select all
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R]


If your server doesn't append trailing slashes automatically, you can try something like this:
Code: Select all
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ http://%{HTTP_HOST}/$1/ [R]
Brett
 
Posts: 82
Joined: Tue Jul 10, 2001 4:00 pm
Location: yohost.com


Return to Beginner's Corner

Who is online

Users browsing this forum: Google [Bot] and 53 guests

cron