Page 2 of 2 First 12
  • Jump to page:
    #16
  1. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1100

    Example 6: domain.com/foo.html -> www.domain.com/foo.html (forcing "www")


    Code:
    RewriteCond %{HTTP_HOST} !^www [NC]
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    Code:
    http://domain.com -> http://www.domain.com
    This rule set externally redirects all requests to the same request on the current domain while adding www. to that domain if it doesn't exist. The [R=301] flag indicates this is an external redirect and that the server should send a 301 Moved server response with the redirect.

    Related Threads: only prefix www if no other subdomain exists, RE: Example forcing "www"

    Comments on this post

    • gimp agrees
    • codergeek42 agrees : Thanks again for all your hard work. This is an excellent guide. :)
    • jabba_29 agrees
    Last edited by jharnois; November 22nd, 2005 at 02:10 AM. Reason: Added related thread.
  2. #17
  3. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1100

    http://domain.com -> https://domain.com (forcing "https")


    Code:
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
    Code:
    http://domain.com/foo.html -> https://domain.com/foo.html
    This rule set externally redirects all requests to the same request on the current domain, but over a secure protocol / connection.

    Related Threads: Redirect to secure URL, Force HTTPS on secure.domain.com

    Comments on this post

    • sarav_dude agrees
    Last edited by jharnois; July 20th, 2007 at 08:26 PM. Reason: Added related thread.
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo