带有多个变量的URL的Mod_Rewrite [英] Mod_Rewrite for URL with multiple variables

查看:79
本文介绍了带有多个变量的URL的Mod_Rewrite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的.htaccess文件中包含以下代码

I have the following code in my .htaccess

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

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

它对于一个变量非常有效,但是我想传递一些其他变量,并且希望它们像第一个一样上升.因此,我没有/about/?anotherVar = extra了,而是有了/about/extra.附加变量将出现在某些页面上,而不是全部

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

我现在有:

#<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 QSA取代了&%{QUERY_STRING}

PS the QSA replaces the &%{QUERY_STRING}

这篇关于带有多个变量的URL的Mod_Rewrite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆