Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jan 2003
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Howto convert domain.com to www.domain.com automagically?

    Hi All, and welcome to my first post here

    A simple question (with a simple answer I hope!).

    If you goto http://php.net/ it will automatically change it to http://www.php.net/. I want to do this with one of my domains. I have full root access so can do anything that is required (although dropping in an htaccess would be the neatest way for me).

    Anyone know how to do it?

    Thanks

    Amy

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, usually it is the way you have your DNS and zones set up.

    If you have a zone for www. then there shouldn't be a problem with using either. However to change it to www. every time, you are right, you would have to use a .htaccess file.

    I have put together a quick rewrite rule that you should just stick in your .htaccess file:

    Code:
    RewriteEngine On
    Options +FollowSymlinks
    RewriteBase /
    
    # domain.com -> www.domain.com
    RewriteCond %{HTTP_HOST} domain.com
    RewriteCond %{REQUEST_URI} !domain.com/ 
    RewriteRule ^(.*)$ www.domain.com [L]
    Like I say, I did that real quick and haven't tested it. Plus I am no guru at .htaccess.

    Give it a try and see what heppens If it doesn't work, just remove it

    Oh and keep me posted

    ::] krycek [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #3
    New Coder
    Join Date
    Jan 2003
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I already have both domain.com and www.domain.com pointing to the same place so both work. I am thinking about PR and google

    OK I ended up using this.

    RewriteEngine On
    Options +FollowSymlinks
    RewriteCond %{HTTP_HOST} !^www\.domain\.com
    RewriteRule ^.*$ http://www.domain.com%{REQUEST_URI} [R=301,L]

    Not exactly what you said, but as soon as I saw what you did say I realised my mistake before... I hadn't got the FollowSymlinks in there!!!

    So, THANK YOU VERY MUCH

    Amy

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Glad it works

    BTW - did mine work? Did you try it? Or just jump straight in with yours? I am just wondering if I got it right, lol

    ::] krycek [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #5
    New Coder
    Join Date
    Jan 2003
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nope, I just saw my mistake and went straight ahead with mine. Tell you what, I've got to nip out but when I get back I'll stick yours in to see if it works and let you know the outcome

    Thanks again

    Amy

  • #6
    New Coder
    Join Date
    Jan 2003
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by krycek BTW - did mine work?
    Yep

  • #7
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Cool!

    I haven't had much experience doing .htaccess files etc. so it is good to know that I did it right

    Is there any particular difference in function between the two...?

    I am just curious because you took a different approach and I am trying to compare them and learn the difference etc.

    ::] krycek [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #8
    New Coder
    Join Date
    Jan 2003
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Don't ask me lol.. looks like regexp hell. I just used that from what someone gave me but didn't work until I realised that I must have symlinks auto off in my httpd.conf. Oh well.

    The 301s are return codes, but that's about it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •