【问题标题】:Trying to hide .htaccess file试图隐藏 .htaccess 文件
【发布时间】:2012-08-03 15:01:08
【问题描述】:

我正在尝试隐藏我的 .htaccess 文件,这样每个人都不能只在浏览器中读取它。

我的 .htaccess 文件位于:http://businessgame.be/.htaccess 如您所见,您仍然可以将其读出。

我尝试添加以下内容:

# secure htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>

还有

<FilesMatch "^\.ht">
Order allow,deny
Deny from all
</FilesMatch>

但似乎都不起作用。这真的很奇怪。我做错什么了吗?

【问题讨论】:

  • 你使用的是什么操作系统?
  • 你确定你使用的是 Apache 吗?
  • 这是一个运行 apache 的 linux 服务器。重写条件有效,为什么 htaccess 只能部分工作?
  • 我在尝试查看该 URL 时收到 403 Forbidden。对我来说似乎很好。
  • 是的,我无法通过 .htaccess 弄清楚,所以我只是通过 Apache 服务器配置它来隐藏它。

标签: file .htaccess hide


【解决方案1】:

您只需按照 .htaccess 文件的示例代码...

<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
<IfModule mod_rewrite.c>
RewriteEngine On
ErrorDocument 404 /404.php
</IfModule>
Options -Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(yourwebsite.com)(:80)? [NC]
RewriteRule ^(.*) http://www.website.com/$1 [R=301,L]
DirectoryIndex index.php       
order deny,allow
Header unset ETag
FileETag None

<FilesMatch "\.(jpg|png|gif|js|css|ico|swf)$">
Header set cache-Control: "max-age=572800, must-revalidate"
</FilesMatch>

这对我们更有帮助.....

否则它会帮助你......

  <Files ~ "\.html$">
Order allow,deny
Deny from all
Satisfy All
</Files>
<Files ~ "\.css$">
Order allow,deny
Deny from all
Satisfy All
</Files>

否则它会运作良好..我会在我的网站上检查此代码。

  Options +FollowSymlinks
 # Prevent Directoy listing 
Options -Indexes
# Prevent Direct Access to files
# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/ 
RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

感谢您....为您提供机会发布...

【讨论】:

    【解决方案2】:

    这是我的服务配置,它可以工作,你应该尝试同样的:

    # secure htaccess file
        <files .htaccess>
            order allow,deny
            deny from all
        </files>
        <FilesMatch "\.(htaccess|htpasswd)$">
            Order Allow,Deny
            Deny from all
        </FilesMatch>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-12
      • 2015-12-14
      • 2010-11-25
      • 2019-04-01
      • 2016-04-16
      • 2020-07-05
      • 1970-01-01
      相关资源
      最近更新 更多