微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

htaccess 文件夹和文件异常不起作用

如何解决htaccess 文件夹和文件异常不起作用

我在 htaccess 中有指令让所有请求都通过 index.PHP 文件。但它禁止访问文件夹和文件。因此,如果我尝试转到 /uploads/products/thumbs/file.png 它会导致 index.PHP?lang=en&category=uploads&section=products (etc) 而不是从我添加文件夹中获取文件 RewriteCond 为现有的添加例外文件文件夹,但由于某种原因它不起作用。

RewriteEngine On
RewriteBase /

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

RewriteRule ^([a-z0-9_\-\.\(\)]+)?$ index.PHP?lang=en&category=$1&section=products [QSA,L]
RewriteRule ^([a-z0-9_\-\.\(\)]+)/([a-z0-9_\-\.\(\)]+)?$ index.PHP?lang=en&category=$1&category_lvl2=$2&section=products [QSA,L]
RewriteRule ^([a-z0-9_\-\.\(\)]+)/([a-z0-9_\-\.\(\)]+)/([a-z0-9_\-\.\(\)]+)?$ index.PHP?lang=en&category=$1&category_lvl2=$2&category_lvl3=$3&section=products [QSA,L]

解决方法

以下列方式拥有您的 htaccess 规则文件。在测试您的网址之前,请务必清除浏览器缓存。

RewriteEngine On
RewriteBase /
##Conditions with rules for URL 3 levels of slashes here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9_\-\.\(\)]+)/([a-z0-9_\-\.\(\)]+)/([a-z0-9_\-\.\(\)]+)?$ index.php?lang=en&category=$1&category_lvl2=$2&category_lvl3=$3&section=products [QSA,L]

##Conditions with rules for URL 2 levels slashes here.       
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9_\-\.\(\)]+)/([a-z0-9_\-\.\(\)]+)?$ index.php?lang=en&category=$1&category_lvl2=$2&section=products [QSA,L]

##Conditions with rules for URL 1 level slash here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9_\-\.\(\)]+)?$ index.php?lang=en&category=$1&section=products [QSA,L]

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。