【问题标题】:How To redirect Multiple Alternate URLs to a parent URL through HTACCESS如何通过 HTACCESS 将多个备用 URL 重定向到父 URL
【发布时间】:2017-08-18 11:24:28
【问题描述】:

我的网站有这个父 URL

 https://www.xyz.de

还有其他 URL 可以访问我的网站,如下所示:

Alternate URL 1: http://xyz.de/index.php
Alternate URL 2: https://www.xyz-zvb.de/index.php
Alternate URL 3: http://www.xyz-zvb.de/index.php
Alternate URL 4: http://xyz-zvb.de/index.php 
Alternate URL 5: www.xyz-zvb.de/index.php

但是现在我想每次用户使用备用网站 url 访问网站时将所有这些 URL 重定向到主父站点 URL,它将重定向到父主 URL。

我尝试过如下方式,但在这种情况下,只能重定向一个 URL,我认为这不是一种推荐的方式。

Redirect 301 /contact.php http://example.com/contact-us.php

关于此任务的任何帮助?

【问题讨论】:

    标签: php .htaccess url redirect url-redirection


    【解决方案1】:

    您可以在站点根目录 .htaccess 中使用此规则:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{THE_REQUEST} \s/+index\.php[?/\s] [NC]
    RewriteRule ^ https://www.xyz.de/ [L,NE,R=301]
    

    【讨论】:

    • 微妙之处太多了,很难全部看出来
    【解决方案2】:

    使用它:

    # Permanent URL redirect
    Redirect 301 /index.php https://www.xyz.de
    

    如果 xyz-zvb.de 或 www.xyz-zvb.de

    # Permanent URL 
    Redirect 301 / https://www.xyz.de
    

    【讨论】:

    • 试试吧,添加到htaccess文件@Shoaib
    猜你喜欢
    • 2021-04-02
    • 2012-03-12
    • 2013-08-30
    • 2017-04-15
    • 1970-01-01
    • 2016-06-11
    • 2020-05-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多