Rewrite problems

Discussion in 'Apache' started by ian_ok, Apr 2, 2006.

  1. #1
    This is my rewite:

    RewriteRule ^property_details/propertiesforsale-([0-9]*).html /property_details/listingview.php?listingID=$1

    So now all links on my websites are as such:
    site . com/property_details/propertiesforsale-55.html

    which all work fine.

    But when you click on a link from Google etc, such as:
    site . com/property_details/listingview.php?listingID=68

    This page loads and you are not redirected to propertiesforsale-68.html

    If I change the rewrite round I get 404 errors:
    RewriteRule ^/property_details/listingview.php?listingID=$1 htt p://w ww.site . com/property_details/propertiesforsale-([0-9]*).html


    [edit] Even if I add
    redirect 301 /property_details/listingview.php?listingID=55 htt p://w ww.site . com/property_details/propertiesforsale-55.html

    It doesn't work, can you have a redirect 301 and a rewrite for the same file???


    Thanks Ian
     
    ian_ok, Apr 2, 2006 IP
  2. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #2
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^property_details/propertiesforsale\-([0-9]*)\.html$ property_details/listingview.php?listingID=$1
    RewriteRule ^property_details/listingview\.php?listingID\=([0-9]*)$ http://www.site.com/property_details/propertiesforsale-$1.html [R=301,L]
     
    Nintendo, Apr 3, 2006 IP
  3. ian_ok

    ian_ok Peon

    Messages:
    551
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi Nintendo, Sorry but it doesn't work.

    Not sure what the problem could be, I had the same problem with another file using the same d/b....so guess that all my links on the site point to the new .html so in time the .php?listingID=$1 will drop out of G and other SE's.

    Ian
     
    ian_ok, Apr 3, 2006 IP
  4. ian_ok

    ian_ok Peon

    Messages:
    551
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    What I've done is to create a 301 for the file listingview.php:
    <?php
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: ht tp://w ww.site.com");
    exit(); ?>

    And re-named the file that rewrites listingview_2 and changed the .htaccess

    I think this will be better?????

    Ian
     
    ian_ok, Apr 3, 2006 IP
  5. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #5
    I'm guessing you got the infinite loop, while on my server it is able to both change the URL, and redirect to the new URL!!
     
    Nintendo, Apr 3, 2006 IP
  6. mihaidamianov

    mihaidamianov Well-Known Member

    Messages:
    1,434
    Likes Received:
    111
    Best Answers:
    0
    Trophy Points:
    190
    #6
    Some hosting services are really bad at handling mod_rewrites. Netfirms.com, for example, gives me a lot of trouble with this. Maybe it's your case too.
     
    mihaidamianov, Apr 3, 2006 IP
  7. ian_ok

    ian_ok Peon

    Messages:
    551
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks for that, I presume you mean an infinite loop is because the URL links have been changed to point to the .html (which doesn't exist) and then you are trying to write anything that accesses the the real file via the the old URL....Not very well explained....!

    eg.
    1st For any requests for w ww.site.com/property_details/propertiesforsale-20.html use the listingview.php file but write the URL as requested

    2nd For any requests for w ww.site.com/property_details/listingview.php?listingID=20 write this as w ww.site.com/property_details/propertiesforsale-20 but this causes the infinte loop as in plain old English terms.....

    ...It doesn't know if it's coming or going!

    Ian
     
    ian_ok, Apr 3, 2006 IP
  8. sarathy

    sarathy Peon

    Messages:
    1,613
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Sorry for bringing up this old thread.,

    I too have the same problem and thought of posting it here itself instead of a new thread.,

    Our old urls was like:
    mysite.com/js/listings.php?emp=abcd-100&pg=12


    I rewrote this urls to:
    mysite.com/india/abcd-100/12/

    All But yahoo searchengine still crawls our old url.

    Now i want to redirect
    all urls in the format:
    mysite.com/js/listings.php?emp=abcd-100&pg=12 to:
    mysite.com/india/abcd-100/12/

    Pls help :)
     
    sarathy, Apr 12, 2006 IP
  9. ian_ok

    ian_ok Peon

    Messages:
    551
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #9
    What i did to oover come this is the following:

    #listingview
    RewriteRule ^property_details/propertiesforsale-([0-9]*).html /property_details/listingview1.php?listingID=$1
    RewriteRule ^property_details/propertiesforsale.html /property_details/listingview1.php

    listingview.php was the original file that I wanted to rewrite and whould have the same problem as yourself so I made a file called listingview1.php exactly the same as listingview.php and changed the htaccess as above then with listingview.php I added the following to redirect to the home page, that way the bots will recrawl the new HTML url's and delist the old .php file

    <?php
    header("HTTP/1.1 301 Moved Permanently"); 
    header("Location: ht tp://w w w.site.com"); 
    exit(); ?>
    Code (markup):
    Best of luck Ian
     
    ian_ok, Apr 12, 2006 IP
  10. sarathy

    sarathy Peon

    Messages:
    1,613
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Thanks for your suggestion ian, :)

    But we have several urls like this and its not possible for us to create a page like that :(

    Is there any other suggestion
     
    sarathy, Apr 13, 2006 IP