Seo And Rewrite Rule

Discussion in 'Apache' started by jason360, Jan 30, 2013.

  1. #1
    Hey guys,

    I am using the following mod_rewrite rule for shortened SEO friendly links:

    RewriteRule ^blog/([^/]*)\.html$ /blog/blog.php?pid=$1 [R=301,L]

    For Google SEO reasons, will the shortened rewritten link created from above be the permanent link, from the R=301? Even though the longer link is still functional?

    Or, do I need to create a rewritematch 301 rule to push the long url to the shortened url permanently?

    Thanks for the help! Much appreciated.

    JK
     
    jason360, Jan 30, 2013 IP
  2. jason360

    jason360 Peon

    Messages:
    7
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    3
    #2
    Ok..I just realized the rewriterule doesn't work with the [R=301,L] tag. Any idea how to make this 301 to the shortened link.

    Original long link sample:

    http://www.example.com/blog/blog.php?pid=great-article
     
    jason360, Jan 30, 2013 IP
  3. jason360

    jason360 Peon

    Messages:
    7
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    3
    #3

    I tried using this, but then the short url just redirects to the long one:

    RedirectMatch 301 /blog/blog.php?pid=(.*)$ http://www.example.com/blog/$1.html
     
    jason360, Jan 30, 2013 IP
  4. ryan_uk

    ryan_uk Illustrious Member

    Messages:
    3,983
    Likes Received:
    1,022
    Best Answers:
    33
    Trophy Points:
    465
    #4
    Try this (I'm at work, so I haven't tested it):

    RewriteRule ^blog/([^/]*)\.html$ /blog/blog.php?pid=$1 [L]
    Code (markup):
     
    ryan_uk, Jan 31, 2013 IP
  5. jason360

    jason360 Peon

    Messages:
    7
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    3
    #5
    Thanks Ryan. I figured it out this morning. This is what I did if anyone else has the same issue:


    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /blog/blog\.php\?pid=([a-z0-9]+)\ HTTP/ [NC]
    RewriteRule ^blog/blog\.php$ http://www.example.com/blog/%1? [R=301,L]
     
    RewriteRule ^blog/([-a-z0-9]+)$ /blog/blog.php?pid=$1 [NC,L] 
    Code (markup):
     
    jason360, Jan 31, 2013 IP
  6. jason360

    jason360 Peon

    Messages:
    7
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    3
    #6
    jason360, Jan 31, 2013 IP
    ryan_uk likes this.