简体   繁体   English

多个文件名的RewriteRule

[英]RewriteRule for multiple file names

I was always using the next: 我一直在使用下一个:

RewriteRule ^(.*)/$ page.php?name=category&type=$1 [L]

to rewrite my links. 重写我的链接。 I used only ONE file name "page.php", and it worked. 我只使用了一个文件名“ page.php”,就可以了。 Today, I want to add another file "project.php", and need another RewriteRule for it, and this is the full code I'm trying to use in .htaccess: 今天,我想添加另一个文件“ project.php”,并需要另一个RewriteRule,这是我试图在.htaccess中使用的完整代码:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

RewriteRule ^(.*)/$ page.php?name=category&type=$1 [L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)/$ project.php?category=$1&id=$4&type=$2&name=$3 [L]

But, it work only for the first path, and messes the second. 但是,它仅适用于第一个路径,而弄乱了第二个路径。 Please, can anyone help to figure it out? 请,有人可以帮忙弄清楚吗? I've tried to search for it for a while, but couldn't find a solution. 我已经尝试搜索了一段时间,但找不到解决方案。 Many thanks in advance! 提前谢谢了!

As Jonathan Kuhn said (.*) read all chars so put project.php rule as first and use at least ([^/]+) in place of (.*) in that rule. 正如乔纳森·库恩(.*) Jonathan Kuhn)所说的(.*)阅读所有字符,因此将project.php rule放在第一位,并至少使用([^/]+)代替该规则中的(.*) ([^/]+) read one or more chars except / . ([^/]+)读取一个或多个字符,但/除外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM