简体   繁体   中英

Apache Mod Rewrite keep get parameters

Firstly I'm no expert with mod rewrite but I have a URL I need to redirect.

The original URL is categories.asp?cat1=1&cat2=2&cat3=58&cat4=96

I need that to redirect to /store/browse/category/TRADITIONAL-BRIDGE-SINK-MIXER/product-details/1901-Traditional-Bridge-Sink-Mixer-NDSMC

Obviously there will be a lot of these to do and I'm happy enough to write each rule in turn.

I hope that makes sense.

Thanks in advance.

I guess there is much more to do and not only with mod_rewrite.

You first would need to achieve this:

  • allow to store the URL parts somewhere in the database for each category and product (probably based on language)
  • show the URL for the products by concatenating these URL parts for each category until the concrete product
    • let's say keyword for category that the product is linked to will be TRADITIONAL-BRIDGE-SINK-MIXER , keyword for that product will be 1901-Traditional-Bridge-Sink-Mixer-NDSMC
    • then You can generate this URL: /store/browse/category/TRADITIONAL-BRIDGE-SINK-MIXER/product-details/1901-Traditional-Bridge-Sink-Mixer-NDSMC
  • then in .htaccess You would have something like this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^store\/browse\/category\/(.*)\/product-details\/(.*)$ product.php?category_id=$1&product_id=$2 [QSA,L] 

The same way for categories, lets say for a URL /store/browse/category/SINK-MIXER/TRADITIONAL-BRIDGE-SINK-MIXER/1901-Traditional-Bridge-Sink-Mixer-NDSMC You would have a rule like:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^store\/browse\/category\/(.*)\/(.*)\/(.*)$ categories.php?category1_id=$1&category2_id=$2&category3_id=$3 [QSA,L] 

This is not a solution, this is just a point to start from...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM