【问题标题】:Return HTTP Status Code 301 for all pages ending on .php为所有以 .php 结尾的页面返回 HTTP 状态代码 301
【发布时间】:2014-09-23 01:00:06
【问题描述】:

如何重定向我网站上所有在 URL 中包含 /de/.php 或 /en/.php 的页面?我不想重定向 domain.com/index.php,只重定向 domain.com/de/.php 或 /en/*.php。

【问题讨论】:

  • 301 重定向,对,但是...去哪里?
  • 只到主域,所以到 domain.com

标签: .htaccess http redirect


【解决方案1】:

你可以使用这条规则

RewriteRule ^(en|de)/(.*?)\.php$ / [R=301,L]

【讨论】:

  • 谢谢!我将它添加到我的 .htaccess 但 domain.com/de/test.php 仍然给我一个 404 而不是 301。
  • 您之前是否设置过 RewriteEngine ?您的 htaccess 在根文件夹中吗?您的 Apache 配置中是否启用了 mod_rewrite 并允许 htaccess ?
  • 我做了,但是 .htaccess 很长,在底部它不起作用。我在 RewriteEngine On 之后立即将它向上移动,现在它就像一个魅力。谢谢!
猜你喜欢
  • 1970-01-01
  • 2019-07-15
  • 2015-05-12
  • 2011-11-18
  • 2022-01-24
  • 2019-10-25
  • 1970-01-01
  • 2012-02-11
  • 1970-01-01
相关资源
最近更新 更多