.htaccess redirecting domain alias'

半腔热情 提交于 2020-01-21 07:35:25

问题


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]

回答1:


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.



来源:https://stackoverflow.com/questions/5901079/htaccess-redirecting-domain-alias

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!