.htaccess 301 redirect for subfolder

Discussion in 'Apache' started by Borduhh, Jan 10, 2012.

  1. #1
    Hey Guys,

    I am trying to redirect a portion of my website to avoid duplicate content issues.

    Right now if you visit my site these are separate pages:

    http://www.mysite.com/blog

    and

    http://www.mysite.com/blog/
    --

    I am trying to redirect every URL in my blog ONLY to the URL without the trailing slash. However I do not want this rule to apply for URLs for my main site (http://www.mysite.com).

    Any suggestions?

    Best Regards,
    Nick
     
    Borduhh, Jan 10, 2012 IP
  2. Borduhh

    Borduhh Well-Known Member

    Messages:
    767
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    150
    #2
    So I figured the rewrite will look something like this:

    
    rewritecond %{http_host} ^mysite.com/blog [nc]
    rewriterule %{http_host} ^mysite.com/blog/ [r=301,nc]
    
    Code (markup):
    But I might be off by a mile here... any ideas guys?
     
    Borduhh, Jan 10, 2012 IP
  3. Borduhh

    Borduhh Well-Known Member

    Messages:
    767
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    150
    #3
    Ok so I found a code that might work

    RewriteCond %{REQUEST_URI} ^/blog/$
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]

    I just have two questions:

    1. What does the $ in /blog/$ mean and I need it to say anything after /blog so I think I might have to have it look like /blog/* or something.
    2. What does the $1 mean in http://%{HTTP_HOST}/$1/

    2.
     
    Borduhh, Feb 2, 2012 IP