Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 阻止在重定向后访问域中的子文件夹_Regex_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Regex 阻止在重定向后访问域中的子文件夹

Regex 阻止在重定向后访问域中的子文件夹,regex,.htaccess,mod-rewrite,redirect,Regex,.htaccess,Mod Rewrite,Redirect,假设我有下面的“mydomain.com”指向文件夹“public_html” 我想将所有mydomain.com重定向到mydomain.com/prod/public文件夹,因此我编辑了.htaccess文件,如下所示: RewriteEngine on RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$ RewriteCond %{REQUEST_URI} !^/prod/public/ RewriteCond %{REQUEST_FILENAME

假设我有下面的“mydomain.com”指向文件夹“public_html”

我想将所有mydomain.com重定向到mydomain.com/prod/public文件夹,因此我编辑了.htaccess文件,如下所示:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteCond %{REQUEST_URI} !^/prod/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /prod/public/$1

RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteRule ^(/)?$ prod/public/index.php [L]
这些改变如预期的那样有效,耶

如何阻止通过以下请求访问站点:

http://mydomain.com/prod/public/


将此规则作为第一条规则放在
prod/public/.htaccess
文件中:

RewriteEngine on

# direct access forbidden
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+prod/public(/index\.php|/?)?[\s?] [NC]
RewriteRule ^ - [F]

很抱歉,在您输入
http://mydomain.com/prod/public/index.php
在浏览器中显示正常内容?prod或prod/public中是否有.htaccess?选项-重写条件%{REQUEST_FILENAME}上的多视图重写引擎-已重写COND%{REQUEST_FILENAME}-f RewriteRule^index.php[L]对于404,您可以将
RewriteRule^-[f]
替换为
RewriteRule^-[L,R=404]
RewriteEngine on

# direct access forbidden
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+prod/public(/index\.php|/?)?[\s?] [NC]
RewriteRule ^ - [F]