【问题标题】:Exclude folder in .htaccess排除 .htaccess 中的文件夹
【发布时间】:2013-10-27 21:43:24
【问题描述】:

每当我尝试访问其中包含电子商务的新创建的文件夹 /shop/ 时,我都会收到 403 Forbidden 错误。如果我直接输入 /shop/index.php 就可以了,但这对访问者来说不是一个可行的选择。 我已经尝试了几种我设法找到的解决方案,但没有一个奏效。你能帮帮我吗?我想完全排除 /shop/ 文件夹的规则并使用电子商务规则。

以下 .htaccess 文件位于根 public_html 文件夹中,是导致此问题的原因:

Options -Indexes
Options +FollowSymLinks
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^teksti/([^./]+)([/]?)$ teksti.php?niceid=$1 [T=application/x-httpd-php,L]
RewriteRule ^clanki/([^./]+)([/]?)$ clankistran.php?niceid=$1 [T=application/x-httpd-php,L]
RewriteCond %{HTTP_HOST} .*www.xmarket.com
RewriteRule ^$ sportna_prehrana.php [T=application/x-httpd-php,L]

RewriteRule ^stran.php$ sportna_prehrana.php%{QUERY_STRING} [T=application/x-httpd-php,L,R=301]
RewriteRule ^cart.php$ nakup.php%{QUERY_STRING} [T=application/x-httpd-php,L,R=301]

RewriteRule ^xfit/$ xfit/xfit.php
RewriteRule ^forum/$ forum/index.php

#Redirect permanent page_wellness.php xfit/

#RewriteRule ^internet.html$ internet.php?%{QUERY_STRING} [T=application/x-httpd-php,L]
#RewriteRule ^programska_oprema.html$ programska_oprema.php?%{QUERY_STRING} [T=application/x-httpd-php,L]
#RewriteRule ^storitve.html$ teksti.php?act=storitve&%{QUERY_STRING} [T=application/x-httpd-php,L]
#RewriteRule ^podjetje.html$ teksti.php?act=opodjetju&%{QUERY_STRING} [T=application/x-httpd-php,L]
#RewriteRule ^pogoji.html$ teksti.php?act=pogoji&%{QUERY_STRING} [T=application/x-httpd-php,L]
#RewriteRule ^privatnost.html$ teksti.php?act=privatnost&%{QUERY_STRING} [T=application/x-httpd-php,L]
#RewriteRule ^stran.html$ stran.php?aktualno=1&%{QUERY_STRING} [T=application/x-httpd-php,L]
#RewriteRule ^podjetje/([^./]+).html$ stran.php?nicepod=$1&%{QUERY_STRING} [T=application/x-httpd-php,L]
#RewriteRule ^([^./]+).html$ stran.php?nicecat0=$1&%{QUERY_STRING} [T=application/x-httpd-php,L]
#RewriteRule ^([^./]+)/a/([^./]+).html$ stran.php?nicecat0=$1&niceart=$2&%{QUERY_STRING} [T=application/x-httpd-php,L]
#RewriteRule ^([^./]+)/([^./]+).html$ stran.php?nicecat0=$1&nicecat1=$2&%{QUERY_STRING} [T=application/x-httpd-php,L]
#RewriteRule ^([^./]+)/([^./]+)/a/([^./]+).html$ stran.php?nicecat0=$1&nicecat1=$2&niceart=$3&%{QUERY_STRING} [T=application/x-httpd-php,L]
#RewriteRule ^([^./]+)/([^./]+)/([^./]+).html$ stran.php?nicecat0=$1&nicecat1=$2&nicecat2=$3&%{QUERY_STRING} [T=application/x-httpd-php,L]
#RewriteRule ^([^./]+)/([^./]+)/([^./]+)/a/([^./]+).html$ stran.php?nicecat0=$1&nicecat1=$2&nicecat2=$3&niceart=$4&%{QUERY_STRING} [T=application/x-httpd-php,L]
ErrorDocument 404 /404.php
#DirectoryIndex page_wellness.php
#DirectoryIndex sportna_prehrana.phpRewriteCond %{HTTP_HOST} ^xy.com$ [OR]
DirectoryIndex vstop.php

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^page_wellness.php$ "http\:\/\/www\.xy\.com\/xfit\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^page_wellness.php/$ "http\:\/\/www\.xy\.com\/xfit\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^xfit/urednik/$ "http\:\/\/www\.xy\.com\/xfit\/urednik\/index\.php" [R=301,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^xfit/podstrani/$ "http\:\/\/www\.xy\.com\/xfit\/podstrani\/index\.php" [R=301,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^kontakti/$ "http\:\/\/www\.xy\.com\/kontakti\/index\.php" [R=301,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^sportno_drustvo\.php$ "http\:\/\/www\.xy\.com\/sdx\/" [R=301,L]

【问题讨论】:

    标签: php html apache .htaccess web


    【解决方案1】:

    不知道你尝试了什么......除了添加休闲重写条件和规则应该可以解决问题:

    RewriteCond %{REQUEST_URI}  !^/shop
    RewriteRule ^.*$ index.php [NC,L]
    

    在这个线程上有一个类似的例子:htaccess - do not rewrite in this case

    还有一些关于这个的教育信息:https://webmasters.stackexchange.com/questions/9513/htaccess-execution-order-and-priority

    正如 las 帖子中所述,您可以从 Apache Tutorial: .htaccess 了解很多关于 .htaccess 文件的信息

    【讨论】:

    • 感谢您的快速回复。我已经尝试过您的解决方案,所以我将您的代码放在“RewriteEngine On”下。现在我不再收到 403 错误,而是这个 html 输出:“网站当前不可用。请稍后再试”。对我来说,它看起来像是一条自定义消息。
    • @MemFaction:商店文件夹中有哪些文件?您可能还必须在 /shop 文件夹中添加一个 .htaccess 文件,以使其具有特定的文件夹(网站)重写规则。在 shop 文件夹中创建一个简单的 index.php 文件并对其进行测试!
    • shop 文件夹中已经有 index.php,它实际上是一个库存的 Opencart 安装。我只能通过直接打开 /shop/index.php 来访问 Opencart。 .htacess 文件当前未在 shop 文件夹中启用。你建议在里面放什么?默认值没有任何作用。
    • 这里有一个更新:如果我在 public_html 中重命名 .htaccess,/shop/ 文件夹有效,但在所有其他页面上我收到消息:“网站当前不可用。请稍后再试”。如果我将您的代码放入 .htaccess,我会在所有页面上收到该消息,即使在 /shop/ 中也是如此。
    猜你喜欢
    • 2013-07-17
    • 2012-11-30
    • 2023-04-03
    • 2015-12-11
    • 2010-12-15
    • 1970-01-01
    • 2011-01-20
    • 1970-01-01
    相关资源
    最近更新 更多