Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.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

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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.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
Php 301使用.htaccess重定向不适用于多个参数_Php_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Php 301使用.htaccess重定向不适用于多个参数

Php 301使用.htaccess重定向不适用于多个参数,php,apache,.htaccess,mod-rewrite,redirect,Php,Apache,.htaccess,Mod Rewrite,Redirect,我实际上想将我的旧网站url重定向到新网站url 我已使1个重定向正常工作 比如说 http://www.abc-old.com/test to http://www.abc-new.com/test123 但问题是,当我有多个slug或参数时,它不会对我起作用 像 我想重定向 http://www.abc-old.com/test1/test2 to http://www.abc-new.com/test1 但它就像重定向一样 http://www.abc-old.com/test1/t

我实际上想将我的旧网站url重定向到新网站url

我已使1个重定向正常工作

比如说

http://www.abc-old.com/test to http://www.abc-new.com/test123
但问题是,当我有多个slug或参数时,它不会对我起作用

我想重定向

http://www.abc-old.com/test1/test2 to http://www.abc-new.com/test1
但它就像重定向一样

 http://www.abc-old.com/test1/test2 to http://www.abc-new.com/test1/test2
下面是我的代码

Redirect 301 /test1/test2 http://www.abc-new.com/test1

如果您的.htaccess文件看起来像/或者httpd.conf包含此文件,请帮助我整理此文件,它应该可以工作

Options +FollowSymLinks
RewriteEngine on
Redirect 301 /test1/test2 http://www.abc-new.com/test1
也许这会很有趣


您可以在旧主机的根目录中使用此规则。htaccess:

RedirectMatch 301 "/test1/test2(/.*)?$ http://www.abc-new.com/test1$1

他知道我是怎么解决的,但还是不明白为什么会发生这种事

例如,我有3个URL

http://www.old.com/test1/
http://www.old.com/test1/test2
http://www.old.com/test1/test2/test3
我在.htaccess中创建了301个重定向,比如

Redirect 301 /test1/ http://www.new.com/test1
Redirect 301 /test1/test2/ http://www.new.com/test2
Redirect 301 /test1/test2/test3 http://www.new.com/test3
在这种情况下

当我请求的时候

http://www.old.com/test1/ is redirected to http://www.new.com/test1

在本例中,当服务器执行.htaccess时,第一个url重定向正在工作,而不是我的第二个url重定向正在工作,另外的参数正在通过test2,所以它是新的重定向

我写过这样的代码

Redirect 301 /test1/test2/test3 http://www.new.com/test3
Redirect 301 /test1/test2/ http://www.new.com/test2
Redirect 301 /test1/ http://www.new.com/test1

它开始工作了。我真的不明白为什么我的第一个代码不起作用,我使用了wordpress CMS,是否需要任何配置?

不起作用选项+FollowSymLinks重定向301上的重写引擎/kaffemaskiner/office coffee这些类型的注释根本没有用。你尝试了什么网址?它导致了404吗?有没有现行的规定?如果是,请在问题中发布。很高兴知道它有效,您可以单击我答案左上角的勾号将答案标记为已接受。
Redirect 301 /test1/test2/test3 http://www.new.com/test3
Redirect 301 /test1/test2/ http://www.new.com/test2
Redirect 301 /test1/ http://www.new.com/test1