Can you help me rewriting-redirecting a URL?

Discussion in 'Programming' started by MyArtGallery, May 25, 2008.

  1. #1
    Please help me redirecting a page. I searched all the internet to fix this problem...but could not find anything. This is my last hope. Please help me:

    I'm trying to rewrite and then reditect the following url for example:
    www.mysite.com/index.php?id_produs=2760

    into this html url:

    www.mysite.com/index.php-id_produs-2760.html

    ...and I added this code but didn't works:
    ----------------------------------------------------------------------
    RewriteEngine on
    RewriteCond %{REQUEST_URI} ^index.php\?id_produs=([a-zA-Z0-9]*)$
    RewriteRule index.php-id_produs-$1.html [R=301]
    -----------------------------------------------------------------------

    I also tried this:
    ------------------------------------------------------------------------
    RewriteEngine on
    RewriteRule -id_produs-(.*)\.html http://www.mysite.com/index.php?id_produs=$1 [R=301]
    -----------------------------------------------------------------------
    The second example works fine regarding the rewriting...but it redirects the page to the php one...not to the html one that I need.

    Can you help me please? Thank you.
     
    MyArtGallery, May 25, 2008 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^index\.php\-id_produs\-([0-9]+)\.html$ index.php?id_produs=$1
    
    Code (markup):
    This should rewrite the request, however, it's not that simple, because all your html will still produce urls like index.php?produs_id=123 ...
     
    krakjoe, May 25, 2008 IP
  3. MyArtGallery

    MyArtGallery Active Member

    Messages:
    418
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Thank you KRAKJOE

    Your code works fine .....but how can I also redirect the old php url to the new html created after rewriting? Just want to avoid to be penalized for duplicate content. You know....the old php are still available using a direct request or in google cache.

    I added this but the browser redirect the html previously created after rewriting the php ...to the php again :
    -----------------------------------------------------------------------------------------
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^index\.php\-id_produs\-([0-9]+)\.html$ index.php?id_produs=$1 [R=301]
    -------------------------------------------------------------------------------------------------
    Once again, the above code does the following:
    1. rewrite php into html
    2. redirect html into php

    But I need this:
    1. rewrite php into html
    2. redirect old php from google cache to the html ones created after rewriting.

    Thank you.
     
    MyArtGallery, May 25, 2008 IP
  4. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #4
    
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^index\.php\-id_produs\-([0-9]+)\.html$ index.php?id_produs=$1
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^index\.php?id_produs=([0-9]+)$ index.php-id_produs-$1.html [R=301]
    Code (markup):
    If I understand correctly ...
     
    krakjoe, May 25, 2008 IP
  5. MyArtGallery

    MyArtGallery Active Member

    Messages:
    418
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #5
    MyArtGallery, May 25, 2008 IP