Redirecting domain.com to www.domain.com?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • james
    Senior Member
    • Mar 2004
    • 183

    Redirecting domain.com to www.domain.com?

    Hi,

    Currently our domains are accessible via http://domain.com and http://www.domain.com.

    Is there any way to have it so http://domain.com redirects to http://www.domain.com instead?

    Cheers,

    James
  • Jonathan
    Senior Member
    • Mar 2004
    • 1229

    #2
    I do not believe you can; I mean you could
    make like index.php go to main.php and make sure
    it has the 'www' part in the URL....

    But basicly you can't make http:// go to
    http://www. because each one it'd access the index file,
    and if it did that, assuming you used index as the forward,
    it'd just keep throwing ppl into a loop of redirection....
    "How can someone be so distracted yet so focused?"
    - C

    Comment

    • james
      Senior Member
      • Mar 2004
      • 183

      #3
      Interesting... Anyone else know how it could be done?

      What about ensuring that the user is using a https:// connection?

      ie. http://www.domain.com/order goes to https://www.domain.com/order

      James

      Comment

      • Jonathan
        Senior Member
        • Mar 2004
        • 1229

        #4
        for the https:// part, why not have all the
        links on your site start with https:// ?
        "How can someone be so distracted yet so focused?"
        - C

        Comment

        • james
          Senior Member
          • Mar 2004
          • 183

          #5
          Yes that would work, i'm just curious as to whether it's possible another way, to ensure a https connection.

          Comment

          • Jonathan
            Senior Member
            • Mar 2004
            • 1229

            #6
            very possibly there may be, but I'm
            at a lost as to how to make sure...

            I'm not sure, but possibly a PHP script?
            That checks if the user is requesting https://domain.com
            and if not (normal http://), then redirect to the https:// ?

            Again, not sure if that can be done...
            "How can someone be so distracted yet so focused?"
            - C

            Comment

            • sdjl
              Senior Member
              • Mar 2004
              • 502

              #7
              The following will check to see if www. is being used. If not, it can be used to force the user to a www. URL:

              PHP Code:
              <?php

              $server 
              getenv("HTTP_HOST");

              if (!
              ereg("^www."$server)) {
                  
              // Assume no www. has been entered
                  
              Header ("Location: http://www.".$server."/");
                  Exit;
                  
              }

              ?>
              If i understand SSL correctly, you should have a seperate location to upload files that are going to be used on your secure site.
              You could use PHP again to look at the $_SERVER['DOCUMENT_ROOT'] var to see that the location is correct, if its not, force the user to the https:// URL.

              David
              -----
              Do you fear the obsolescence of the metanarrative apparatus of legitimation?

              Comment

              • -Oz-
                Senior Member
                • Mar 2004
                • 545

                #8
                David, i added that to the FAQ, tell me if you mind

                It is very easy to make sure that a user uses http://www.domain.com instead of just http://domain.com with a simple piece of PHP code placed at the top of every page. &lt;?php $server = getenv(&quot;HTTP_HOST&quot;); if (!ereg(&quot;^www.&quot;, $server)) { // Assume no www. has been entered Header
                Dan Blomberg

                Comment

                • sdjl
                  Senior Member
                  • Mar 2004
                  • 502

                  #9
                  Nope, that's fine by me Oz

                  David
                  -----
                  Do you fear the obsolescence of the metanarrative apparatus of legitimation?

                  Comment

                  • ndns
                    Junior Member
                    • Apr 2004
                    • 7

                    #10
                    You can also use mod_rewrite in your .htaccess file. Put it inside your public_html directory in order for the changes to effect all files/directories.
                    Code:
                    RewriteEngine On
                    Options +FollowSymlinks
                    RewriteCond %{HTTP_HOST} ^domain\.com
                    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]
                    Replace domain and .com as necessary.

                    Comment

                    • -Oz-
                      Senior Member
                      • Mar 2004
                      • 545

                      #11
                      I have updated the FAQ accordingly http://forums.dathorn.com/showthread.php?p=1656
                      Dan Blomberg

                      Comment

                      Working...