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 301重定向到根目录并删除查询字符串_.htaccess_Redirect - Fatal编程技术网

.htaccess htaccess 301重定向到根目录并删除查询字符串

.htaccess htaccess 301重定向到根目录并删除查询字符串,.htaccess,redirect,.htaccess,Redirect,我正在尝试重定向htaccess中带有查询字符串的各种页面 要重定向的URL示例如下: /item.htm?item_id=ACPEMEG465P-VE&product 我想使用通配符捕获项目_id*之后的任何字母数字 我想重定向到根域并删除查询字符串。因此,在阅读了几本指南后,我得出了以下结论: RewriteCond %{QUERY_STRING} item_id(.*)$ RewriteRule ^item\.htm$ /? [L,R=301] …但这似乎没有任何作用-我只是得

我正在尝试重定向htaccess中带有查询字符串的各种页面

要重定向的URL示例如下:

/item.htm?item_id=ACPEMEG465P-VE&product
我想使用通配符捕获项目_id*之后的任何字母数字


我想重定向到根域并删除查询字符串。因此,在阅读了几本指南后,我得出了以下结论:

RewriteCond %{QUERY_STRING} item_id(.*)$
RewriteRule ^item\.htm$ /? [L,R=301]
…但这似乎没有任何作用-我只是得到一个404。谁能告诉我哪里出了问题?我使用的是Apache2.4.6

以下是htaccess:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# security measures
Header always set X-Frame-Options "sameorigin"
Header always set Referrer-Policy "same-origin"
Header always set Feature-Policy "geolocation 'self'; camera 'none'; microphone 'none'"
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

RewriteCond %{QUERY_STRING} item_id(.*)$
RewriteRule ^item\.htm$ /? [L,R=301]

# BEGIN rlrssslReallySimpleSSL rsssl_version[3.3.4]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
#wpmu rewritecond companydomain.com
RewriteCond %{HTTP_HOST} ^companydomain\.com [OR]
RewriteCond %{HTTP_HOST} ^www\.companydomain\.com [OR]
#end wpmu rewritecond companydomain.com
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
# END rlrssslReallySimpleSSL
重新编写引擎打开
重写基/
重写规则^index\.php$-[L]
#安全措施
标题始终设置X帧选项“sameorigin”
标头始终设置引用者策略“相同来源”
标题始终设置功能策略“地理位置‘自我’;摄像头‘无’;麦克风‘无’”
#在/wp admin中添加尾部斜杠
重写规则^wp admin$wp admin/[R=301,L]
RewriteCond%{REQUEST_FILENAME}-f[或]
RewriteCond%{REQUEST_FILENAME}-d
重写规则^-[L]
重写规则^(wp-(内容|管理|包括)。*)$1[L]
重写规则^(.*\.php)$$1[L]
重写规则。index.php[L]
重写cond%{QUERY\u STRING}项\u id(.*)$
重写规则^item\.htm$/?[L,R=301]
#开始RLRSSSLREALLYSPLESSL rsssl_版本[3.3.4]
重新启动发动机
重写cond%{HTTP:CF Visitor}'方案:“HTTP”'
#wpmu rewritecond companydomain.com
重写cond%{HTTP_HOST}^companydomain\.com[或]
重写cond%{HTTP_HOST}^www\.companydomain\.com[或]
#结束wpmu rewritecond companydomain.com
重写规则^(.*)$https://%{HTTP_HOST}/$1[R=301,L]
#结束rlrssslReallySimpleSSL

我删除了压缩、mod_mime、mod_头和mod_expires的部分,因为它们不相关

RewriteRule . index.php [L]
此规则将所有非文件和非目录重写为
/index.php
,并将
请求URI
变量更新为
/index.php
。因此,您的新规则是:

RewriteCond %{QUERY_STRING} item_id(.*)$
RewriteRule ^item\.htm$ /? [L,R=301]
不会执行,因为
请求\u URI
不再是
/item.htm


一旦您将此规则移动到顶部,它就会起作用,因为
请求\u URI
仍然是
/item.htm

我想重定向到根域并删除所有查询字符串。请确保显示的规则位于.htaccess的顶部,并且.htaccess已启用。我已使用htaccess更新了问题。请在下面插入显示的规则
RewriteBase/
line行了,谢谢。.htaccess中是否有覆盖它的特定规则?