Search code examples
php.htaccessvariablesclean-urlsnice

htaccess two variables two landing pages


i have already implemented and working the following:

http://domain.com/collections/ford

from the following url:

http://domain.com/collections.php?brand=ford

using the

RewriteRule ^collections/$1/(.*)$ collections.php?company=$1 [L]

This works perfectly. Now i need to implement a subcategory on those pages. They should look like:

http://domain.com/collections/ford/classic

from

http://domain.com/collections.php?brand=ford&collection=classic

but instead of using the same php page as previously (collections.php), i want to use a different one (year.php) and two variables.Both year.php and collections.php reside on the root of my site.

The question is how should i modify my htaccess tp achieve the desired result? Thanks a lot for any help.


Solution

  • You can use this code in your DOCUMENT_ROOT/.htaccess file:

    Options +FollowSymLinks -MultiViews
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^collections/([^/]+)/?$ collections.php?company=$1 [L,QSA,NC]
    
    RewriteRule ^collections/([^/]+)/([^/]+)/?$ collections.php?brand=$1&collection=$2 [L,QSA,NC]