使用与另一次重写相同的规则重写时未找到


Not Found when rewriting using same rule as another rewrite

所以我重写了article?id=10article/10,我正试图做另一个这样的。

我想从site?=website.comsite/website.com。好吧,看起来很简单。所以我输入

RewriteRule ^site/([0-9]+)$ site.php?id=$1

这与article重写的规则基本相同。现在我以site/10为例,输入

未找到

请求的URL/site/sdfsd在此服务器上找不到。

为什么会发生这种情况,如果它是相同的事情,其他重写工作良好?....

multiviews方法

选项DirectoryIndex index . phpRewriteEngine

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^article/([0-9]+)$ article.php?id=$1 [L,QSA,NC]
RewriteRule ^site/([0-9]+)$ site.php?id=$1
# rewrite from /dir/file/ to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1'.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]

Try

RewriteRule ^site/(.+)$ site.php?id=$1 [L]

[0-9]+只匹配数字

基本上你的重写规则是坏的

RewriteRule ^site/([0-9]+)$ site.php?id=$1只匹配数字

你可以用

RewriteRule ^site/(.*)$ site.php?id=$1

(通配符)

我不得不说"site/whatever.com"这个表达式实际上指向

site.php?id=whatever.com -反向语句为false

您的规则不匹配,因为角色只允许数字。换句话说,你的规则是:

以"site/"开头,后面跟着数字(0-9)。

你的规则必须是

RewriteRule ^site/([0-9a-zA-Z]+)$ site.php?id=$1

你似乎有两个问题。

[0-9]只匹配数字,所以不能匹配字母。

你还需要在你的规则中添加[L]标志,以确保它在第一次比赛时停止。

RewriteRule ^site/(0-9a-zA-Z+)$ site.php?id=$1 [L]