【问题标题】:htaccess redirects for subdomain and all linkshtaccess 重定向子域和所有链接
【发布时间】:2021-09-20 09:25:09
【问题描述】:

有没有人知道任何 301 .htaccess 规则而不是涵盖网站上的所有链接。举几个例子:

例子:

https://support.olddomain.com/
https://support.newdomain.com/

https://support.olddomain.com/id.php?pp=sdf-sdf-sdf&r=13
https://support.newdomain.com/id.php?pp=sdf-sdf-sdf&r=13

【问题讨论】:

  • 如果您寻找它,您会在 SO 上找到数百个可行的解决方案。
  • 这能回答你的问题吗? Htaccess 301 redirection

标签: php .htaccess


【解决方案1】:

如果两个主机名(即support.olddomain.comsupport.newdomain.com)指向不同的服务器,那么您可以在旧域的.htaccess 文件中使用简单的mod_alias Redirect。例如:

# Redirect everything to the new-domain (like for like URLs)
Redirect 301 / https://support.newdomain.com/

但是,如果两个主机名指向同一个地方,那么您需要使用 mod_rewrite 并明确检查请求的主机名以避免重定向循环。例如:

RewriteEngine On

# Redirect everything to the new-domain (like for like URLs)
RewriteCond %{HTTP_HOST} =support.olddomain.com
RewriteRule ^ https://support.newdomain.com%{REQUEST_URI} [R=301,L]

两组规则做同样的事情......即。 301 将https://support.newdomain.com/<url-path>?<query-string> 重定向到相同的<url-path><query-string> https://support.newdomain.com/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 2014-03-22
    • 2015-02-13
    • 2012-04-19
    • 2013-09-26
    • 2011-07-17
    • 2017-04-22
    相关资源
    最近更新 更多