Forum Moderators: phranque

Message Too Old, No Replies

Checking for WWW?

I need to check if WWW is there and if not add it.

         

reman

2:03 am on Jul 9, 2004 (gmt 0)

10+ Year Member



Hi everyone!

I need one of my sites to be accessed by having the www part of the www.mydomain.com. Users who log in without the www are shown as guest but users who log in www.mydomain.com are not.

Any ideas?
Thanks!
reman

mykel79

9:27 am on Jul 9, 2004 (gmt 0)

10+ Year Member



If your site runs on Apache, try using mod_rewrite. The following will redirect all users that type example.com to www.example.com.
If they type in example.com/somefile.html they'll be sent to www.example.com/somefile.html

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com$1 [R=301]

This must be placed either in your Apache configuration file, or a text file called .htaccess in the root directory of your site.

reman

11:24 am on Jul 9, 2004 (gmt 0)

10+ Year Member



WOW! Thanks!

Just want to double check something. When you say root do you mean right under public_html OR the level above public_html? ie in the level that shows public_html, www, temp etc?

Just want to put it in the right spot.

Again, MANY THANKS!
reman

PS Great forum...I am a newbie at this!

reman

11:32 am on Jul 9, 2004 (gmt 0)

10+ Year Member



Hmmm

When typing [mysite.net...] it did indeed redirect to www. But when typing [mysite.net...] it stated: The page cannot be displayed.

What now? I put the htaccess file in the public_html dir.

Any ideas?
reman

mykel79

11:43 am on Jul 9, 2004 (gmt 0)

10+ Year Member



By root I meant the directory where the index file of the domain is located (the file that loads when you type [example.com...] Sorry for not being clear on that.

As for it not working: is mamboserver a file or a directory? If it's a directory, does it work when you type in [mysite.net...] (with a slash at the end)?

reman

11:47 am on Jul 9, 2004 (gmt 0)

10+ Year Member



No. It does NOT load the site using your code. It is a directory. I had tried adding
RewriteCond %{HTTP_HOST} ^herspace2\.net/mamboserver/ [NC]

reman

[edited by: reman at 11:53 am (utc) on July 9, 2004]

reman

11:48 am on Jul 9, 2004 (gmt 0)

10+ Year Member



OK, wrong. I had added the mambo part. Just your code will not work at for any /xyz/ part.

reman

reman

12:35 pm on Jul 9, 2004 (gmt 0)

10+ Year Member



How could I get something like this to work?

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.* [NC]
RewriteRule (.*) [mysite.*...] $1 [R=301]

ie anything with mysite needs to be changed to www.mysite?

I saw this but it did not work
RewriteEngine on
RewriteRule ^/$ /e/www/ [R]

Thanks!
reman

reman

1:03 pm on Jul 9, 2004 (gmt 0)

10+ Year Member



Ok, so if anyone wants to know in the future:

RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} ^herspace2\.net
RewriteRule ^(.*)$ [herspace2.net...] [R=permanent]

Works!

Thanks!
Have a nice one!
reman

[edited by: jatar_k at 5:33 pm (utc) on July 9, 2004]
[edit reason] removed url [/edit]