简体   繁体   中英

Mod_Rewrite for URL with multiple variables

I have the following code in my .htaccess

RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?mode=$1&%{QUERY_STRING})

It works great for one variable but I want to pass some additional variables and would like them to so up like the first one. So instead of having /about/?anotherVar=extra I have /about/extra. The additional variable would be on some pages not all

I now have:

#<IfModule mod_rewrite.c>

#   RewriteEngine on
#    RewriteCond %{REQUEST_FILENAME} !-f
#    RewriteCond %{REQUEST_FILENAME} !-d

#</IfModule>


Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?mode=$1 [QSA]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ index.php?mode=$1&productContent=$2 [QSA]
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?mode=$1 [QSA]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ index.php?mode=$1&anotherVar=$2 [QSA]

PS the QSA replaces the &%{QUERY_STRING}

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