Mod rewrite 条件重写规则-如何仅应用这两组规则中的一组

Mod rewrite 条件重写规则-如何仅应用这两组规则中的一组,mod-rewrite,Mod Rewrite,如果从项目名称开始的第一个位置有按考试浏览或我的研究中心,如 http://project_name/browse_by_exam/type/classes/... http://project_name/my_study_centre/page_sort/1,20,name,asc/... 然后应用以下两条规则:- RewriteRule ^([a-zA-Z0-9\-\_]+)/?$ index.php?a=$1 RewriteRule ^([a-z0-9\-\_]+)/([a-z0-9\

如果从项目名称开始的第一个位置有
按考试浏览
我的研究中心
,如

http://project_name/browse_by_exam/type/classes/...
http://project_name/my_study_centre/page_sort/1,20,name,asc/...
然后应用以下两条规则:-

RewriteRule ^([a-zA-Z0-9\-\_]+)/?$ index.php?a=$1 
RewriteRule ^([a-z0-9\-\_]+)/([a-z0-9\-\_]+)/?$ index.php?a=$1&b=$2
对于所有其他URL,请应用以下规则:-

RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]
谢谢


Sandepan

这些URL中没有一个与您的两条规则的模式相匹配。但如果要编写符合条件的规则,请尝试以下规则:

RewriteRule ^(browse_by_exam|my_study_centre)($|/) foobar [L]

这些URL都不符合您的两个规则的模式。但如果要编写符合条件的规则,请尝试以下规则:

RewriteRule ^(browse_by_exam|my_study_centre)($|/) foobar [L]

我自己找到了解决办法。以下方面发挥了作用:-

############Following rules apply only to browse_by_exam and my_study_centre

RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 ^(browse_by_exam|my_study_centre) 

RewriteRule ^(.*)$ index.php [L,QSA]
#################################################


###Following rules apply to all other pages (other than browse_by_exam and my_study_centre)
RewriteRule ^([a-zA-Z0-9\-\_]+)/?$ index.php?a=$1 

RewriteRule ^([a-z0-9\-\_]+)/([a-z0-9\-\_]+)/?$ index.php?a=$1&b=$2

RewriteRule ^([a-z0-9\-\_]+)/([a-z0-9\-\_]+)/([a-zA-Z0-9\-\_+]+)/?$ index.php?a=$1&b=$2&c=$3

RewriteRule ^([a-z0-9\-\_]+)/([a-z0-9\-\_]+)/([a-zA-Z0-9\-\_+]+)/([0-9]+)/?$ index.php?a=$1&b=$2&c=$3&d=$4
干杯


Sandepan

我自己找到了解决方案。以下方面发挥了作用:-

############Following rules apply only to browse_by_exam and my_study_centre

RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 ^(browse_by_exam|my_study_centre) 

RewriteRule ^(.*)$ index.php [L,QSA]
#################################################


###Following rules apply to all other pages (other than browse_by_exam and my_study_centre)
RewriteRule ^([a-zA-Z0-9\-\_]+)/?$ index.php?a=$1 

RewriteRule ^([a-z0-9\-\_]+)/([a-z0-9\-\_]+)/?$ index.php?a=$1&b=$2

RewriteRule ^([a-z0-9\-\_]+)/([a-z0-9\-\_]+)/([a-zA-Z0-9\-\_+]+)/?$ index.php?a=$1&b=$2&c=$3

RewriteRule ^([a-z0-9\-\_]+)/([a-z0-9\-\_]+)/([a-zA-Z0-9\-\_+]+)/([0-9]+)/?$ index.php?a=$1&b=$2&c=$3&d=$4
干杯


Sandepan

@skaffman我想我应用了有意义的标签,为什么要删除这些标签?因为这是一个关于mod rewrite的问题,而这正是人们将要寻找的标签。标签是用来分类的,而不是用来描述的。@skaffman我想我应用了有意义的标签,你为什么要删除这些标签?因为这是一个关于mod rewrite的问题,这是人们将要寻找的标签。标签是用来分类的,不是用来描述的。谢谢你的回答,但我没有弄清楚。。。如果你能举我的例子…谢谢你的回答,但我没有弄清楚。。。如果你能用我的例子说明。。