问题描述
我的基本问题是我在 vps apache 服务器中使用 node.js 服务器。
所以在 /public_html 目录中的 .htaccess 文件中
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
DirectoryIndex disabled
RewriteEngine On
RewriteRule ^$ http://127.0.0.1:35112/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:35112/$1 [P,L]
而且我的节点应用程序一切正常。
但是,在 public_html/site-1/ 和/或 public_html/site-2/ 内部,您会看到我有其他子目录,其中包含不同的内容,例如其他 wordpress 网站以及您拥有的内容。
那么上面的 .htaccess 代码最终会发生什么
DirectoryIndex disabled
从本质上阻止其他 public_html 子目录工作,但我删除了该行然后我的节点应用程序主页不起作用。
我的问题基本上是有没有办法可以禁用 public_html/ 的父目录,但保留子目录,例如 public_html/site-1/ 和/或 public_html/site-2/ 单独工作?
感谢您的帮助。
解决方法
您可以在子目录中使用不同的 .htaccess 文件,并指定:
DirectoryIndex homepage.html
无关:
一个小提示:
您可以将 RewriteBase
用于 mod_rewrite。
RewriteBase /subdir
RewriteRule ^/file.html - [F,L]
# This will deny access to the file.html
#...more rewrite rules for subdir