调整Apache mod_rewrite RewriteRule不要对物理目录起作用

时间:2021-05-25 20:00:18

I have this RewriteRule that works too well :-)

我有这个RewriteRule,效果很好:-)

RewriteRule ^([^/]*)/$ /script.html?id=$1 [L]

The bad thing about this rule is that it also matches physical directories which I don't want.

这个规则的坏处是它也匹配我不想要的物理目录。

How can I tell the mod_rewrite to ignore physical directories and apply the above rule only when the directory matched does not exist?

如何告诉mod_rewrite忽略物理目录并仅在匹配的目录不存在时才应用上述规则?

2 个解决方案

#1


3  

Take a look at RewriteCond. Put the following before your rule to exempt out directories and files

看看RewriteCond。在规则之前放置以下内容以免除目录和文件

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

#2


0  

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/$ /script.html?id=$1 [L]

#1


3  

Take a look at RewriteCond. Put the following before your rule to exempt out directories and files

看看RewriteCond。在规则之前放置以下内容以免除目录和文件

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

#2


0  

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/$ /script.html?id=$1 [L]