Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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
Apache 正在使用.htaccess删除URL的一部分。重写后的404_Apache_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

Apache 正在使用.htaccess删除URL的一部分。重写后的404

Apache 正在使用.htaccess删除URL的一部分。重写后的404,apache,.htaccess,mod-rewrite,url-rewriting,Apache,.htaccess,Mod Rewrite,Url Rewriting,我对我的重写感到困惑。我想做以下工作: example.com/不需要/index.php→ example.com/index.php example.com/不需要/folder/→ example.com/folder/ 应保留查询参数 我已经有了一个重写规则来完成这项工作: Options +FollowSymlinks -MultiViews RewriteEngine On RewriteBase / RewriteRule ^not/needed(.*)$ $1 [L,R=

我对我的重写感到困惑。我想做以下工作:

  • example.com/不需要/index.php→ example.com/index.php
  • example.com/不需要/folder/→ example.com/folder/
  • 应保留查询参数
我已经有了一个重写规则来完成这项工作:

Options +FollowSymlinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteRule ^not/needed(.*)$ $1 [L,R=302,QSA]

然而在重写之后,我得到了404。我如何告诉服务器它应该显示来自原始URI的内容?

您的规则只在一个方向起作用<代码>重写规则,没有什么魔法能让它反向运行。您需要显式创建一个执行相反操作的规则:

Options +FollowSymlinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \ /+not/needed/(.*)
RewriteRule ^not/needed(.*)$ $1 [L,R=302]

RewriteCond %{REQUEST_URI} !^/not/needed/
RewriteRule ^(.*)$ /not/needed/$1 [L]