SEO and Mod_Rewrite Help - what is the best solution?

Discussion in 'Apache' started by cmcash, Jan 24, 2009.

  1. #1
    Hello,

    I am new to .htaccess and I am trying to make SEO friendly links with it. But I have some doubts that maybe you can help me on that.


    First question:
    ==========

    I have implemented a rewrite rule for my product-category pages as

    RewriteCond %{HTTP_HOST} ^mysite.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.mysite.com$
    RewriteRule ^product-category.php/cat([0-9]+)$ "/products-search.php\?catid\=$1"

    Since in this case I am just rewriting the link and not doing a redirection is this SEO friendly?

    And now, how can I avoid that search engines index my pages using the dynamic versions of my links? i.e., I don't want the dynamic links like "products-search.php?catid=..." to be indexed because it would generate duplicated content right?
    What is the best approach to avoid it?



    Second question:
    ==========

    Since I want to implement static links for each one of my products like for instance

    RewriteRule ^nice-scented-soap.php$ "/product.php\?pid\=MSC-00015"

    what is the best approach to do it? since I am a lot of products how to avoid to do an individual rule for each one of them? Using Rewrite maps?


    Thanks in advance for your precious help.

    Best regards and have a nice weekend.
     
    cmcash, Jan 24, 2009 IP
  2. pr0t0n

    pr0t0n Well-Known Member

    Messages:
    243
    Likes Received:
    10
    Best Answers:
    10
    Trophy Points:
    128
    #2
    I would do that this way:

    
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^product-category\.php/cat([0-9]+)$ /products-search.php?catid=$1 [L]
    RewriteRule ^product-category\.php/cat([0-9]+)/$ /products-search.php?catid=$1 [L]
    
    Code (markup):
    This was for your first question. As for your second question, that's going to be the problem. If you want to use some special names for each product, then your script has to be capable to pull that product by fetching a name, and not that mark MSC-00015. If this is what your script needs to show some product, then you could do it this way:

    
    RewriteRule ^([^/]+)\.html$ /product.php?pid=$1 [L]
    
    Code (markup):
    Remember to add those first lines "RewriteEngine On" and "RewriteBase /" if you are NOT just adding this rules after those in first question. If you are adding it after those rules, then you do not need to repeat this lines...
    So, this second rule will for example fetch every request for yourdomain.com/MSC-00015.html to yourdomain.com/product.php?pid=MSC-00015
    Or you could manually enter some custom name for each product... :cool:
    PS: You could try to use .php as well, instead of .html but that might create some mess on your account if you have some php script that you still need to hit directly without being redirected by you rrewrite rules.
     
    pr0t0n, Jan 24, 2009 IP
  3. cmcash

    cmcash Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks a lot for your help related to my questions.

    But I have still one doubt. How to avoid that search engines index the dynamic links? Because if they index them then I would get duplicated content right?

    Thanks in advance if someone can help me on that question.

    Best regards.



     
    cmcash, Jan 25, 2009 IP