【问题标题】:.htaccess Rewrite except one subfolder.htaccess 重写除了一个子文件夹
【发布时间】:2026-01-25 13:45:01
【问题描述】:

我的 .htaccess 中有一些重写规则,我想添加一个异常子文件夹,以便当用户链接到该子文件夹时 mod_rewrite 停止重写。

我的特殊子文件夹是http://simplyservices.gr/aivali 当有人到达这个网址时,mod_rewrite 遵循我添加的规则,最后用户看不到 aivali 的内容 这是我的 .htaccess

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/aivali/ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]*)\.html$ /new1/products.php?kategory=$1 [L]
RewriteRule ^([^/]*)/([^/]*)\.html$ /new1/products.php?kategory=$1&subkategory=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html$ /new1/products.php?kategory=$1&subkategory=$2&id=$3 [L]

我已经尝试了同一篇文章中提到的所有内容,但没有任何效果。我认为我的 RewriteRules 出了点问题。

谢谢

【问题讨论】:

    标签: php apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    RewriteConds 只屏蔽下面的每个 RewriteRule。

    因此,您的 !-f!-d!-d 检查仅适用于第一次。一开始这可能是多余的,除非真的有dir/dir/*.html 文件。

    现在更有趣的是RewriteCond %{REQUEST_URI} !^/aivali/ [NC] 也只是掩盖了第一个 RewriteRule。然而,第一个 RewriteRule 只匹配 basename.html,而不是像 aivali/sub.html 这样的东西

    您应该将该 RewriteCond 异常移到第二个 RewriteRule 前面,因为那是主要捕获它的那个。

    【讨论】: