使用 .htaccess 隐藏文件夹

发布于 2024-08-04 03:07:40 字数 78 浏览 2 评论 0原文

是否可以隐藏根文件夹中的文件夹? 以防我的index.php消失你知道吗?

如果有人请求,我还可以显示 404 错误未找到吗?

Is it possible to hide the folders in my root folder?
Just in case my index.php would disappear you know?

Could I also show 404 error not found if someone requests them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

茶色山野 2024-08-11 03:07:40

您想要的可能是,

Options -Indexes

如果没有找到 DirectoryIndex 文件,只会给出 404 错误。

What you want is probably

Options -Indexes

which will just give a 404 error if no DirectoryIndex file is found.

挽袖吟 2024-08-11 03:07:40
IndexIgnore *

以上将阻止列出所有文件。这里 * 充当通配符。如果需要,您可以将其替换为更具体的内容。

IndexIgnore *

The above would prevent all files from being listed. Here * acts as a wildcard. You could replace it with something more specific, if needed.

俏︾媚 2024-08-11 03:07:40

正如 duskwuff 所提到的,您需要的是

Options - Indexes

这将在该特定目录上导致 403 禁止错误。因此,要提供自定义错误页面,您将需要

ErrorDocument   403 myErrorPage.html

希望这有帮助

As mentioned by duskwuff, what you need is

Options - Indexes

This will cause a 403 forbidden error on that particular directory. Thus to provide a custom error page you will need

ErrorDocument   403 myErrorPage.html

Hope this helps

青丝拂面 2024-08-11 03:07:40

如果您确实想显示子文件夹的 404 错误,请在 /.htaccess 中尝试以下操作:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [R=404,L]

如果存在 /folder/subfolder ,则上述规则会将其重写为 /404

If you really want to show a 404 error for subfolder(s) , try the following in /.htaccess :

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [R=404,L]

If an existent /folder or /subfolder is requested, the above rule will rewrite it to /404 .

红颜悴 2024-08-11 03:07:40

我通过在我不想访问的所有文件夹上添加一个index.html 来解决这个问题。 index.html 页面包含一行,其中包含以下 header("Location:thepageiwanttoshown.html")。这样,如果用户意外访问受限文件夹,他们将被即时重定向。我希望它有帮助

I get around this by adding an index.html on all folders i dont want accessed. The index.html page contains a single line with the following header("Location:thepageiwanttoshown.html"). This way if the user accidentally visits the restricted folders they will be redirected on the fly. I hope it helps

红颜悴 2024-08-11 03:07:40

这是我针对同一问题的首选解决方案(不过,这会显示拒绝访问而不是 404):

<files "/path/to/single/file/or/folder">
  order allow,deny
  deny from all
</files>

这还为您提供了授予对某些 IP 的访问权限的选项(在这种情况下,它拒绝对所有 IP 的访问)

“/path/to/如果您想使用模式,则可以将“single/file/or/folder”替换为正则表达式。否则,您必须对要阻止访问的每个特定文件或文件夹使用多个阻止。

This was my preferred solution to the same problem (this displays an Access Denied instead of 404 though):

<files "/path/to/single/file/or/folder">
  order allow,deny
  deny from all
</files>

This also gives you the option to give access to certain IP's (in this case it deny's access to all)

The "/path/to/single/file/or/folder" can be replaced with regex if you want to use a pattern instead. Otherwise you have to use multiple blocks for each specific file or folder that you want to block access to.

绝不服输 2024-08-11 03:07:40

就我而言,我这样做了,但它显示错误 500。这是我的 .htaccess

RewriteEngine on

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Options - Indexes

谢谢

In my case, i did that but it shows me Error 500. This is my .htaccess

RewriteEngine on

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Options - Indexes

Thanks

此生挚爱伱 2024-08-11 03:07:40

对我来说,它总是可以添加

<Directory "/var/www/yourfolder"> IndexIgnore * </Directory>

到文件 /etc/apache2/sites-available/default

For me it always works with adding

<Directory "/var/www/yourfolder"> IndexIgnore * </Directory>

to the file /etc/apache2/sites-available/default

平生欢 2024-08-11 03:07:40

我使用了这段代码:

在你的主根 .htaccess 中放置以下代码:

RewriteEngine on
RewriteRule ^dfjgekbjvrskzcnfvberidurvf/?(.*)$    /folder1/$1 [L]


Then at .htaccess file in folder1 directory put this :

RewriteEngine on
RewriteCond %{THE_REQUEST} !dfjgekbjvrskzcnfvberidurvf
RewriteRule ^    - [F,L]

I used this code:

At your main root .htaccess put the flowing code :

RewriteEngine on
RewriteRule ^dfjgekbjvrskzcnfvberidurvf/?(.*)$    /folder1/$1 [L]


Then at .htaccess file in folder1 directory put this :

RewriteEngine on
RewriteCond %{THE_REQUEST} !dfjgekbjvrskzcnfvberidurvf
RewriteRule ^    - [F,L]
我的鱼塘能养鲲 2024-08-11 03:07:40

在要隐藏文件夹列表的目录中创建一个文件 mame .htaccess 并仅包含此代码

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [R=404,L]

make a file mame .htaccess in the directory where you want to hide folder's list and just this code

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [R=404,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文