【问题标题】:PHP Redirect 301 - .htaccessPHP 重定向 301 - .htaccess
【发布时间】: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


【解决方案1】:

检查 mod-rewrite 是否处于活动状态。在您的 Apache 配置中,应该有一个未注释的语句,例如 LoadModule rewrite_module modules/mod-rewrite.so。如果已注释,请取消注释并重新启动服务器。之后,将以下内容放入stand 目录中:

RewriteEngine On
RewriteRule ^index\.php(.*)$ https://%{HTTP_HOST}/stand-carros-usados$1 [R=301,L,NC]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-30
    • 2021-04-01
    • 2012-11-25
    • 2011-05-01
    • 2011-01-03
    • 2012-03-10
    • 2021-07-22
    • 1970-01-01
    相关资源
    最近更新 更多