Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/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重定向到新url_.htaccess_Redirect - Fatal编程技术网

.htaccess htaccess重定向到新url

.htaccess htaccess重定向到新url,.htaccess,redirect,.htaccess,Redirect,我有下面的网址 www.site.com/Photo/Actor/ActorName/GalleryName/2 这里 Photo和Actor是url中的静态字符串 ActorName和GalleryName是动态的 2是照片索引 如何将此url模式重定向到以下位置 www.site.com/Actor/ActorName/GalleryName/Photo/2 我正在更改我的网站url格式。 我的站点已经在google中进行了良好的爬网和索引,因此我想将URL重定向到新格式,

我有下面的网址

   www.site.com/Photo/Actor/ActorName/GalleryName/2
这里 PhotoActor是url中的静态字符串
ActorNameGalleryName是动态的
2是照片索引

如何将此url模式重定向到以下位置

    www.site.com/Actor/ActorName/GalleryName/Photo/2
我正在更改我的网站url格式。 我的站点已经在google中进行了良好的爬网和索引,因此我想将URL重定向到新格式,以便当前索引的URL不会消亡。

您可以使用:

    <?php

header("Location: http://www.mydomain. com/new-page.html", true, 301);
exit();
?>


要了解更多信息:

您可以按如下方式动态重写它:

RewriteRule ^(Photo)/(Actor)/([^/]+)/([^/]+)/([0-9]+)$ /$2/$3/$4/$1/$5 [R=302,NC,L]
进一步解释:

^(Photo)/(Actor)/([^/]+)/([^/]+)/([0-9]+)$
这意味着,如果它以
Photo/Actor/ActorName/GalleryName/Numbers
开头

然后使用301永久重定向重定向到
Actor/ActorName/GalleryName/Photo/Numbers

/$2/$3/$4/$1/$5
表示上述产品的重新排序


请记住,我正在对上述代码使用
R=302
,您也应该使用
R=302
,直到您确认它完全符合您的需要,然后您可以安全地将其切换到
R=301

这是为了防止您的浏览器在以前的尝试中被缓存,这样您就可以看到它是否工作,直到它确定为止


如果您之前已经尝试过,我建议您使用不同的浏览器测试URL,最好是您没有使用过的浏览器,以确保它不会访问缓存的信息。

您是否已经有了
.htaccess
?您是否正在使用WordPress或类似的CMS?是的。我正在使用.htaccess实现所有重定向。不使用CMS。当然。。实现它目前…完美。此重定向正在工作。。不是htaccess方面的专家。学习它。@ChiranjeeviPadala很高兴它对你有用:)如果你想阅读和了解更多,这里有一个很好的mod_rewrite介绍。谢谢你的建议和解决方案。
RewriteRule ^Photo/Actor/([^/]+)/([^/]+)/(\d+)  Actor/$1/$2/Photo/$3  [L,R=301]