【发布时间】:2018-01-23 15:30:33
【问题描述】:
M1: 这可以从根目录重定向到子目录
# .htaccess main domain to subdirectory redirect
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subdirectory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /subdirectory/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ subdirectory/index.html
M2: 这可以拒绝直接访问 root
.htaccess 在根目录(public_html)
Order deny,allow
Deny from all
然后使用它允许直接访问子目录
.htaccess 在子目录中
Allow from all
网站结构
public_html
|___ subdirectory ___ index.php
|___ .htaccess
|___ app
|___ something.php
当我添加它们时,example.com 都给出了
您无权访问此服务器上的 /。
第一次更改 .htaccess 中的任何内容
编辑
我想要做的是阻止对子目录以外的任何内容的直接访问。
如果
RewriteRule ^(.*)$ ?page=$1 [NC]
添加到子目录会和它冲突
【问题讨论】:
-
不清楚你想要什么。您是要阻止对
app文件夹的访问,还是要阻止对subdirectory以外的任何文件夹的访问? -
除了子目录@anubhava之外的任何东西
-
子目录将包含 index.php、css、js 和 img 任何必须直接访问的内容@anubhava
-
应该允许
example.com/something.php吗? -
不,只有子目录可以直接访问其他内部的东西,比如 PHP @anubhava 的包含和请求
标签: apache .htaccess redirect mod-rewrite