htaccess的重定向域别名“别名、重定向、htaccess

2023-09-02 00:35:14 作者:清风挽去

我有了域别名一个良好的数额,并希望他们都重定向到该网站上的一个主域的客户端。他们也想知道哪些域别名做重定向。我有一部分下来,但我想优化code到最好最正确的方法应该是,消除了code我写的金额。我想知道是否有一种方法传递给URL重写规则所使用的域别名。

这是我现在有。我找的是被击中,然后传递一个别名URL的域别名。然后,在谷歌分析,我可以看到多少次,该网址是用来打的页面。

 的RewriteCond%{HTTP_HOST} ^(WWW )?域alias1  .COM [NC]
重写规则^(。*)http://www.main-domain.com/?domain-alias1.com$1 [R = 301,L}
 

但我的目标是没有写这两个条件,规则为每一个域别名。

有没有办法,看看哪些别名被击中,然后让重写规则自动添加到我指定的位置?

linuxshell编程之bash别名 快捷键及输入输出重定向

本来我试过这样的事情只是为了看看它是否会工作(虽然我已经尝试了许多不同的方法):

 的RewriteCond%{HTTP_HOST} ^(WWW )?([AZ] +)。com [NC]
重写规则^(。*)http://www.main-domain.com/?$1.com$2 [R = 301,L]
 

解决方案

您可以尝试沿着这些路线的东西:

 的RewriteCond%{HTTP_HOST}!^(WWW )?主域 .COM $ [NC]
重写规则^(。*)http://www.main-domain.com/$1?domain=%{HTTP_HOST} [R = 301,L]
 

通过这个任何请求不会作为域 www.main-domain.com 将被重定向到 www.main -domain.com 在查询字符串域名

I have a client that has a good amount of domain alias' and wants them all redirected to the one main domain on the site. They also want to know which of the domain alias' is doing the redirecting. I have that part down but I want to optimize the code to the best most proper way it should be and to eliminate the amount of code I have to write. I am wanting to know if there is a way to pass to the RewriteRule url the domain alias that was used.

This is what I have now. I am looking for the domain alias that is being hit and then passing that alias to the url. Then in google analytics I can see how many times that url was used to hit the page.

RewriteCond %{HTTP_HOST} ^(www.)?domain-alias1.com [NC]
RewriteRule ^(.*) http://www.main-domain.com/?domain-alias1.com$1 [R=301,L}

But my goal is to not have to write both the condition and rule for every single domain alias.

Is there a way to see which alias was hit and then have the rewrite rule automatically add that to the position I have specified?

I had originally tried something like this just to see if it would work(although I have tried many different ways):

RewriteCond %{HTTP_HOST} ^(www.)?([a-z]+).com [NC]
RewriteRule ^(.*) http://www.main-domain.com/?$1.com$2 [R=301,L]

解决方案

You can try something along these lines:

RewriteCond %{HTTP_HOST} !^(www.)?main-domain.com$ [NC]
RewriteRule ^(.*) http://www.main-domain.com/$1?domain=%{HTTP_HOST} [R=301,L]

With this any request NOT for domain www.main-domain.com will be redirected to www.main-domain.com with the domain name in query string domain.