对不同的文件夹使用重写

Kne*_*ZOD 4 mod-rewrite url-rewriting

我目前在根文件夹上有我所有的php文件,我使用这个Rewrite Rule,它工作正常:

ErrorDocument 404 /broken.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} ^/(index(\.(html|htm)))?$
RewriteRule %{REQUEST_URI} / [L,R,QSA]
RewriteCond %{REQUEST_URI} !^/(index(\.(html|htm)))?$
RewriteRule ^([_a-zA-Z0-9]+)/?$ /$1.php [L,QSA]
Run Code Online (Sandbox Code Playgroud)

我目前打算修改它,以便我可以重写查询字符串,如contact/test/yes成为contact.php?test = yes

我的问题是:如果我有一个我需要重写的子文件夹(例如root/subfolder1); 我如何重写此子文件夹1中的规则,以便contact/test/yes不会将某些内容解释为在测试文件夹内的yes文件,该文件位于联系人文件夹中?

感谢您之前的所有帮助.

Pat*_*ery 17

你可以创建每个案例或动态

注意:如果存在文件夹,则需要添加:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Run Code Online (Sandbox Code Playgroud)

如果您创建每个案例,则必须指定每个子文件夹,如:

RewriteRule ^contact/test/([_a-zA-Z0-9]+)/?$ /contact.php?test=$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)

如果它是动态的你将必须处理主php文件中的每个页面然后在该文件中创建一个逻辑来解析正确的信息:

RewriteRule ^([a-z0-9\-]+)/([a-z0-9\-]+)/([_a-zA-Z0-9]+)/?$ /index.php?page=$1&subpage=$2&lastpage=$3 [L,QSA]
Run Code Online (Sandbox Code Playgroud)