所以当谈到htaccess时我不是英雄。如果我在下面有完整错误的代码,请原谅我。
以下是示例链接(在每个链接的后面是一个数字,我将反驳它应该链接到哪个htaccess部分):
website.com/home/ #1
website.com/home/page2/ #1
website.com/projects/ #1 or #2 (doesnt matter since the first GET will be page in both cases)
website.com/projects/staticpage/ #1
website.com/projects/filter1/ #2
website.com/projects/filter1/filter2/ #2
我目前使用的代码是(第1部分):
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/projects/$
RewriteRule ^([-A-Za-z0-9-_]+)/?$ index.php?page=$1 [L,QSA]
RewriteRule ^/?([-A-Za-z0-9-_]+)/([-A-Za-z0-9-_]+)/?$ index.php?page=$1&sub=$2 [L,QSA]
RewriteRule ^/?([-A-Za-z0-9-_]+)/([-A-Za-z0-9-_]+)/([-A-Za-z0-9-_]+)/?$ index.php?page=$1&sub=$2&sub-sub=$3 [L,QSA]
htaccess的另一部分(第2部分):
RewriteEngine On
RewriteBase /
RewriteRule ^([-A-Za-z0-9-_+]+)/?$ index.php?secondpart=$1 [L,QSA]
RewriteRule ^/?([-A-Za-z0-9-_+]+)/([-A-Za-z0-9-_+]+)/?$ index.php?secondpart=$1&filter[]=$2 [L,QSA]
RewriteRule ^/?([-A-Za-z0-9-_+]+)/([-A-Za-z0-9-_+]+)/([-A-Za-z0-9-_+]+)/?$ index.php?secondpart=$1&filter[]=$2&filter[]=$3 [L,QSA]
过滤器是动态的,因此无法排除它们。
当网址等于: website.com/projects / 时,我会跳过第一部分,但是,
当我将网址更改为: website.com/projects/filter1 / 时,我无法抓住第二部分。
如果你能帮我解决这个问题,非常感谢你。
答案 0 :(得分:0)
您可以这样做:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_URI} ^/pagesearch/(staticpage1|staticpage2)/
RewriteRule ^ - [L]
RewriteRule ^([\w-]+)/?$ index.php?page=$1 [L,QSA]
RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?page=$1&sub=$2 [L,QSA]