【发布时间】:2015-09-30 11:16:33
【问题描述】:
我想使用 PHP 重定向代码将用户从一个旧页面重定向到一个新页面。我发现了这一点,但现在所有内容都重定向到新页面,只是想跳转到某个特定页面。 这是我使用的代码,它不起作用:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.New-Website.com");
?>
是否有任何选项可以仅指定新网址的子网址?
编辑
我已经尝试过使用 .htaccess,但它在那里不起作用。所以我决定用这种方式。无论如何,这样也有可能吗?顺便说一句,我使用 .htaccess 尝试了两个代码:
RewriteRule ^stand/index.php(.*)$ https://%{HTTP_HOST}/stand-carros-usados$1 [R=301,L]`
和
Redirect 301 stand/index.php(.*) https://%{HTTP_HOST}/stand-carros-usados
但它们都没有真正起作用。
【问题讨论】:
-
你在哪里写的代码?
-
你不能使用 .htaccess 吗?
-
如果问题得到解决,请发布答案和/或将其设为已接受。不要用“已解决!”更新问题
-
感谢 deceze。我在学习
-
RewriteRule ^stand/index.php(.*)$ https://%{HTTP_HOST}/stand-carros-usados$1 [R=301,L]- 这个工作正常。解决了
标签: php .htaccess url-rewriting header url-redirection