gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 07:38:15 24 4
gpt4 key购买 nike

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

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 规则文件。在测试您的 URL 之前,请确保清除浏览器缓存。

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]

关于.htaccess - htaccess 文件夹和文件异常不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67635407/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com