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
Regex 使用正则表达式的通配符301重定向_Regex_.htaccess_Redirect - Fatal编程技术网

Regex 使用正则表达式的通配符301重定向

Regex 使用正则表达式的通配符301重定向,regex,.htaccess,redirect,Regex,.htaccess,Redirect,这方面的任何帮助都将是巨大的,因为我正在努力让它发挥作用 我正在尝试使用以下命令为/pop.php?path=content/执行通配符重定向匹配301重定向 RedirectMatch 301 /pop.php?path=content/.* http://mywebsite.com 但是由于“.”和“=”的原因,它不能正常工作,而且我不擅长正则表达式 谢谢 Steve将其放入站点根目录中的.htaccess文件中: RewriteEngine on RewriteBase / Rewri

这方面的任何帮助都将是巨大的,因为我正在努力让它发挥作用

我正在尝试使用以下命令为
/pop.php?path=content/
执行通配符重定向匹配301重定向

RedirectMatch 301 /pop.php?path=content/.* http://mywebsite.com
但是由于“.”和“=”的原因,它不能正常工作,而且我不擅长正则表达式

谢谢
Steve

将其放入站点根目录中的
.htaccess
文件中:

RewriteEngine on
RewriteBase /

RewriteCond %{QUERY_STRING} path=content [NC]
RewriteRule pop.php http://mywebsite.com/? [R=301,L]

您需要
RewriteCond
来检查查询字符串的值。如果且仅当匹配时,
pop.php
将被重定向到其他站点。

感谢您的帮助。我已经厌倦了你提供的代码,但是我得到了一个404而不是301重定向到根域。谢谢Steve。在
pop.php
中找不到404?它是物理文件还是虚拟路径?该文件不再存在。该文件用于一个旧的PHP gallery脚本,该脚本已从站点中删除。完整路径是您是否启用了
mod_rewrite
,是否将
.htaccess
放在子域站点根目录中?mod_rewrite已启用,并且.htaccess包含在子域的根目录中。我有其他的重写规则正在运行和工作,但我只是努力用某种通配符来解决这个问题,它将301将any/pop.php?path=content/query重定向到子域的根目录。