【问题标题】:Redirect a.com/a.html to b.com/a.html将 a.com/a.html 重定向到 b.com/a.html
【发布时间】:2015-08-24 17:28:44
【问题描述】:

我需要将 a.com/a.html 重定向到 b.com/a.html htaccess Apache。我有几个子域没有被重定向到 b.com(这很好)。下面的示例只是需要重定向的第一个域。还需要将其他三个域重定向到 b.com 以及它们的所有子页面作为 a.com/a.html 到 b.com/a.html。有什么提示吗?

RewriteCond %{HTTP_HOST} ^(www\.)?nexus21\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^tvlift\.com$ [NC]
RewriteRule ^ http://www.tvlift.com%{REQUEST_URI} [L,NE,R=301]

【问题讨论】:

  • 你为什么用 [php] 标记这个?
  • 我的错误。一些重定向是使用 PHP 标头位置完成的

标签: apache .htaccess mod-rewrite


【解决方案1】:

我会分别进行每个子域重定向。这样它更干净,更易于维护。如果您要重定向几个已知文件,请直接命名它们。

RewriteEngine  on
RewriteRule    "^/foo\.html$"  "bar.html"  [R]

如果有很多文件或者你将来会添加,那么使用一个模式

RewriteEngine on
RewriteRule   "^/docs/(.+)"  "http://new.example.com/docs/$1"  [R,L]

查看此页面 http://httpd.apache.org

【讨论】:

    猜你喜欢
    • 2013-08-01
    • 2023-04-04
    • 1970-01-01
    • 2019-01-24
    • 2016-11-02
    • 1970-01-01
    • 1970-01-01
    • 2011-03-15
    • 1970-01-01
    相关资源
    最近更新 更多