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]