如何通过HTACCESS将多个备用URL重定向到父URL

时间:2017-08-18 11:24:28

标签: php .htaccess url redirect url-redirection

我的网站有这个家长网址

 https://www.xyz.de

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

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,我认为这不是一种提供的方式。

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

有关此任务的任何帮助?

2 个答案:

答案 0 :(得分: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]

答案 1 :(得分:0)

使用它:

# 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
相关问题