WordPress.org

Ready to get started?Download WordPress

Forums

Permalinks and mod_rewrite - how to make query url look like directory (7 posts)

  1. Zaphod
    Member
    Posted 3 years ago #

    Ok,

    So I have a car listings site setup with permalinks enabled as standard and it works fine.

    However, there's almost 70k cars on it so I created a custom search page
    where the user selects car make, model, year, price, mileage, colour etc...

    I'm wondering if there's a way to add a rule to the .htaccess file that would convert
    http://www.mysite.com/used-cars/?make=renault&model=clio etc
    to
    http://www.mysite.com/used-cars/renault/clio/

    WITHOUT breaking the normal WP permalinks. I just have the permalink structure set to /%postname%/

    Any help appreciated.

  2. Zaphod
    Member
    Posted 3 years ago #

    Have made a very poor start on this.

    Have created a dummy site non-wordpress site on my local machine using a .html file, one or two php files etc.

    in the .htaccess file I put

    RewriteRule ^used-cars/([0-9a-zA-Z]*)$ /used-cars/$1/
    RewriteRule ^used-cars/([0-9a-zA-Z]*)/$ /ht/?make=$1

    so if I enter
    http://localhost/ht/used-cars/Abjh4/ #URL FOR DEMO ONLY - WON'T WORK

    it shows up as such in the browser but looks for :
    /mypage.php?make=Abjh4
    SO AS SUCH, IT WORKS.

    TWO THINGS.

    1) Above example: can't figure out how to get it to work as follows:
    http://localhost/ht/used-cars/ford/fiesta/
    to show above url but look for
    /mypage.php?make=ford&model=fiesta

    2)If I add this [two rewrite rules above] to the WordPress .htaccess file after the
    # END WordPress
    bit, it makes no difference whatsoever.

    So I need a heads up on how to get a rule that I know works (in one sense) to work with the WP rules and not break anything.

    2)

  3. Zaphod
    Member
    Posted 3 years ago #

    Small update to the above:

    RewriteRule ^used-cars/([0-9a-zA-Z_-]*)/([0-9a-zA-Z_-]*)$ /used-cars/$1/$2/
    RewriteRule ^used-cars/([0-9a-zA-Z_-]*)/([0-9a-zA-Z_-]*)/$ /ht/?make=$1&model=$2

    works to turn
    http://localhost/ht/used-cars/ford/fiesta/
    into (on server end)
    /mypage.php?make=ford&model=fiesta

    ** BUT ** it breaks if I just put

    http://localhost/ht/used-cars/ford/

    saying
    Not Found

    The requested URL /used-cars/ford// was not found on this server.
    *note* TWO trailing slashes at the end...

    One step forward, and two steps back...

  4. Zaphod
    Member
    Posted 3 years ago #

    Just FYI here's my .htaccess

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /mysite/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    #RewriteRule . /carcompare/index.php [L] L denotes LAST - i.e. dont' follow any more Rewrite Rules
    RewriteRule . /mysite/index.php 
    
    </IfModule>
    
    # END WordPress
    
    #RewriteRule ^old\.html$ new.html  THIS ONE WORKS
    RewriteRule ^used-cars/([0-9a-zA-Z_-]*)/([0-9a-zA-Z_-]*)$ /used-cars/$1/$2/
    RewriteRule ^used-cars/([0-9a-zA-Z_-]*)/([0-9a-zA-Z_-]*)/$ /ht/?make=$1&model=$2
  5. Zaphod
    Member
    Posted 3 years ago #

    In the above example normal WP rules work fine, my redirection rules being ignored. The /ht/ bit on the last line is wrong but I'm aware of that - that's not the issue.

  6. Zaphod
    Member
    Posted 3 years ago #

    .... is there anybody out there....

    :-)

    Maybe this just can't be done?

  7. arpitap
    Member
    Posted 3 years ago #

    let me know if you find some solution for this.

    Thanks,
    Arpita

Topic Closed

This topic has been closed to new replies.

About this Topic