从htaccess中标识变量



我使用htaccess传递2个变量。主题&品牌

RewriteRule ^([A-Za-z0-9_-]+)/?$ ?subject=$1 [NC,L]
RewriteRule ^([A-Za-z0-9_-]+)/?$ ?brand=$1 [NC,L]

在我的函数文件中,我使用页面检测来包括相应的模块。

if (!empty($_REQUEST['subject']))
{
    include_once("templates/pages.php");
}
else if (!empty($_REQUEST['brand']))
{
    include_once("templates/brands_content.php");
}

问题:我无法检测变量。。。。它总是加载"templates/pages.php"有人能指导我解决这个问题吗。

感谢

第二条规则RewriteRule ^([A-Za-z0-9_-]+)/?$ ?brand=$1 [NC,L]永远不会匹配,因为无论您请求什么URL,都会匹配第一个URL(针对主题)。主题或品牌的URL显示方式显然没有区别。

http://yourdomain.com/12345

"12345"是一个品牌还是一个主题?您要么需要使正则表达式匹配subject和brand互斥(或者如果不匹配,subject,第一条规则,将始终首先匹配),要么您可以通过将其添加到URI:中来明确地说明什么是品牌或主题

http://yourdomain.com/subject/12345
http://yourdomain.com/brand/12345

因此,你的规则是:

RewriteRule ^subject/([A-Za-z0-9_-]+)/?$ ?subject=$1 [NC,L]
RewriteRule ^brand/([A-Za-z0-9_-]+)/?$ ?brand=$1 [NC,L]

最新更新