.Htacess: Force www and /

Discussion in 'Programming' started by JCOnline, Jan 12, 2013.

  1. #1
    Hi my friends,

    Long time no work. "Htacess" and forgot everything.

    How do I force all pages of a site to have www at the beginning and / in the end.

    example: site.com/page1 to www.site.com/page1/
    www.site.com/page to www.site.com/page1/

    Thanks
     
    JCOnline, Jan 12, 2013 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    The www part is

    RewriteCond %{HTTP_HOST} ^site.com[nc]
    RewriteRule ^(.*)$ http://www.site.com/$1 [r=301,nc]

    I think
    RedirectMatch 301 (.*) //$1
    should take care of the file-to-directory redirect.
     
    Rukbat, Jan 13, 2013 IP
  3. JCOnline

    JCOnline Greenhorn

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    Thanks for the help, but unfortunately it did not work.

    The first code only redirects the homepage. The second adds two bars on all the URLS.
     
    JCOnline, Jan 13, 2013 IP
  4. Dreeass

    Dreeass Member

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    Here's the one I use:
    RewriteEngine On
     
    RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
    RewriteRule .? http://domain.com%{REQUEST_URI} [L,R=301]
    Code (markup):
     
    Dreeass, Jan 20, 2013 IP