Regex Can';不要在目录中重写URL

Regex Can';不要在目录中重写URL,regex,.htaccess,url,mod-rewrite,Regex,.htaccess,Url,Mod Rewrite,这是我的正则表达式 Options -MultiViews DirectoryIndex index.php RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^article/([0-9]+)$ article.php?id=$1 [L,QSA,NC] RewriteRule ^site/(.*)$ site.php?id=$1 [L] R

这是我的正则表达式

Options -MultiViews
DirectoryIndex index.php
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^article/([0-9]+)$ article.php?id=$1 [L,QSA,NC]
RewriteRule ^site/(.*)$ site.php?id=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
这就是我希望我的URL看起来的样子:

http://localhost/developer/site/google.com
所以我会这么做

RewriteRule ^site/(.*)$ site.php?id=$1 [L]
但是当我转到URL时,我得到的只是

找不到

在此服务器上找不到请求的URL/developer/site/google.com


即使我的
developer
文件夹中有一个
site.php
。有什么想法吗?

您必须使用正确的重写路径(
RewriteBase
),前提是您的htaccess位于
developer
文件夹中

另外,请不要忘记,
RewriteCond
仅用于下一个
RewriteRule

Options -MultiViews

RewriteEngine On
RewriteBase /developer/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^article/([0-9]+)$ article.php?id=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^site/([^/]+)$ site.php?id=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/developer/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]