Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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
.htaccess 使用htaccess在URL中隐藏目录不起作用_.htaccess_Mod Rewrite_Mod Security - Fatal编程技术网

.htaccess 使用htaccess在URL中隐藏目录不起作用

.htaccess 使用htaccess在URL中隐藏目录不起作用,.htaccess,mod-rewrite,mod-security,.htaccess,Mod Rewrite,Mod Security,我有website1.com设置,这样当用户访问website1.com时,他们会通过index.html中的meta标记重定向到website1.com/directory 然后他们使用该网站并访问诸如website1.com/directory/index.html之类的链接。我试图在链接中隐藏“目录”,以便用户只能看到website1.com/index.html 我已经在website1.com/directory/.htaccess上放置了htaccess,它将url重写为websit

我有website1.com设置,这样当用户访问website1.com时,他们会通过index.html中的meta标记重定向到website1.com/directory

然后他们使用该网站并访问诸如website1.com/directory/index.html之类的链接。我试图在链接中隐藏“目录”,以便用户只能看到website1.com/index.html

我已经在website1.com/directory/.htaccess上放置了htaccess,它将url重写为website1.com/index.html

我没有做任何其他特别的事情,这应该是一个简单的任务。我目前的确切访问权限如下:

RewriteEngine On
RewriteCondition %{REQUEST_URI} !^directory/
RewriteRule ^(.*)$ directory/$1 [L]
应该很容易吧。。。。。我得到的只是404

在我的服务器中,我有Mod_Rewrite和Mod security,怀疑其中一个是导致此功能无法工作的原因,但无法想象为什么。我是不是遗漏了什么

  • 您的规则不正确,因为
    %{REQUEST\u URI}
    变量已开始
    /
  • 您需要将此文件放在文档根目录中
  • 在文档root.htaccess中使用此代码:

    RewriteEngine On
    RewriteCondition %{REQUEST_URI} !^/directory/
    RewriteRule ^(.*)$ /directory/$1 [L]