【问题标题】:301 Redirection in .htaccess.htaccess 中的 301 重定向
【发布时间】:2019-01-07 18:19:55
【问题描述】:

我正在尝试重定向 URL,使用 .htaccess 文件中的以下行:

redirect 301 /old_file_path /new_file_path

重定向工作正常,但我得到的 URL 格式不同:

/new_file_path/?/old_file_path

我该如何解决这个问题?

【问题讨论】:

  • 像这样单独使用Redirect 指令应该不能首先产生这种效果。 PHP 与此有什么关系?
  • 使用 HTTP 协议/文件夹/文件作为第二个参数,而不是系统路径。参考:apache.com/…
  • 这是您的完整代码吗?好像少了一些零件。另外,这是在哪个操作系统上运行的?
  • 试试RewriteRule ^/old_file_path(.*)$ /new_file_path$1 [R=301,NC,L]
  • 哦,我的错。我使用的代码是这样的:redirect 301 /old_file_path /new_file_path 旧 URL:keleven.com/master-trainer 新 URL:keleven.com/master_trainer_course 我得到的 URL:keleven.com/master_trainer_course/?/master-trainer

标签: .htaccess url-redirection http-status-code-301


【解决方案1】:

请按照以下示例进行操作:

Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html
Redirect 301 /oldpage2.html http://www.yoursite.com/folder/

或与您分享完整的 .htaccess 文件,以便我们更好地查看。

确保 mod_rewrite apachi 模块已打开。

我最后测试了代码,它工作正常。

RewriteEngine on
Redirect 302 /master-trainer https://www.keleven.com/master_trainer_course

希望对你有帮助。

【讨论】:

  • redirect 301 /master-trainer https://www.keleven.com/master_trainer_course这是我用的
  • 它应该可以正常工作我在我的本地主机上测试,它很好。
【解决方案2】:

您应该重定向到完整的新路径:

redirect 301 /old_file_path https://example.com/new_file_path

【讨论】:

  • 一定有办法不用硬编码服务器路径
猜你喜欢
  • 2014-11-25
  • 2011-05-01
  • 2011-01-03
  • 2012-03-10
  • 2021-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多