Mod_Rewrite for URL with multiple variables

橙三吉。 提交于 2019-12-12 20:23:49

问题


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]

回答1:


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}



来源:https://stackoverflow.com/questions/15314832/mod-rewrite-for-url-with-multiple-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!