[英]HTAccess 'Mirror Domain', respecting SSL, respecting co.uk+.com, keeping subdomain and request_uri
I would like to map multiple domains onto a main one for SEO and simplicity purposes. 我想将多个域映射到一个主要域中,以实现SEO和简化目的。
My three domains are 我的三个域是
webdevguru.co.uk
t3chguy.co.uk
mortie.org
I want both of the example domains to get redirected to the main domain, keeping their subdomain and the file and query string the client accessed. 我希望将两个示例域都重定向到主域,同时保留其子域以及客户端访问的文件和查询字符串。
For example: 例如:
str.webdevguru.co.uk => str.webdevguru.co.uk/
webdevguru.co.uk => www.webdevguru.co.uk/
fusion.t3chguy.co.uk => fusion.webdevguru.co.uk/
mortie.org/foo?bar => www.webdevguru.co.uk/foo?bar
https://mortie.org/ => https://www.webdevguru.co.uk/
Basically, I want ALL traffic redirected to the main domain, this also has to respect HTTPS as the domain cms gets transferred to a different URL, my subfolder containing the cms subdirectory files has the following code in the .htaccess. 基本上,我希望所有流量都重定向到主域,这也必须遵守HTTPS,因为域cms被传输到另一个URL,包含cms子目录文件的子文件夹在.htaccess中具有以下代码。
RewriteEngine on
RewriteCond %{HTTP_HOST} ^cms\.webdevguru\.co\.uk$ [NC]
RewriteRule .* https://secure24447.qnop.net/~t3chguy/tools/cms%{REQUEST_URI} [R=301,L]
This second code works absolutely fine I am just showing it to further explain my example. 第二个代码工作得很好,我只是向其展示以进一步解释我的示例。 I keep having issues with any regex I keep trying, it works in one way but not in another, could some people please suggest what I could do to get the above functionality? 我一直在尝试的任何正则表达式都存在问题,它以一种方式起作用,而在另一种方式中却无法起作用,请问有人可以建议我可以做些什么来获得上述功能?
Thanks in Advance 提前致谢
Ok, I give it a try : 好吧,我试试看:
# simple rule to redirect mainexample.co.uk to www.mainexample.co.uk
RewriteCond %{HTTPS} !=on [NC]
RewriteCond %{HTTP_HOST} ^[^\.]+\.(com|co\.uk|org)$ [NC]
RewriteRule ^(.*)$ http://www.mainexample.co.uk/$1 [R=301,QSA,L]
# same, with HTTPS
RewriteCond %{HTTPS} =on [NC]
RewriteCond %{HTTP_HOST} ^[^\.]+\.(com|co\.uk|org)$ [NC]
RewriteRule ^(.*)$ https://www.mainexample.co.uk/$1 [R=301,QSA,L]
# here comes the funny part
RewriteCond %{HTTPS} !=on [NC] # no HTPPS
RewriteCond %{HTTP_HOST} ^(.+)\.(.+)\.(com|co\.uk|org) [NC] # capture the subdomain
RewriteCond %{HTTP_HOST} !mainexample\.co\.uk$ [NC] # we are not on mainexample.co.uk
RewriteRule ^(.*)$ http://%1.mainexample.co.uk/$1 [R=301,QSA,L] # 301 redirection to mainexample keeping the subdomain and the request uri
# same, for HTTPS
RewriteCond %{HTTPS} =on [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.(.+)\.(com|co\.uk|org) [NC]
RewriteCond %{HTTP_HOST} !mainexample\.co\.uk$ [NC]
RewriteRule ^(.*)$ https://%1.mainexample.co.uk/$1 [R=301,QSA,L]
There no need to duplicate rules for http and https, but I don't know how to do one only rule. 无需为http和https复制规则,但是我不知道如何只做一个规则。
Edit regarding your HTTPS issue : 编辑有关您的HTTPS问题:
RewriteCond %{HTTPS} =on [NC]
RewriteCond %{HTTP_HOST} ^(cms|fusion)\.[^\.]+\.(com|co\.uk|org)$ [NC]
RewriteRule ^(.*)$ https://secure27.qnop.net/~t3chguy/%1/$1 [R=301,QSA,L]
You can use these rules: 您可以使用以下规则:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^cms\.mainexample\.co\.uk$ [NC]
RewriteRule .* https://secure24447.qnop.net/~t3chguy/tools/cms%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^[^.]+\.webdevguru\. [NC]
RewriteRule ^ - [L]
RewriteCond %{HTTP_HOST} ^webdevguru\. [NC,OR]
RewriteCond %{HTTP_HOST} ^(?:www\.)?mortie\.org$ [NC]
RewriteRule ^ http%{ENV:protossl}://www.webdevguru.co.uk%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.[^.]+\.[^.]+\. [NC]
RewriteRule ^ http%{ENV:protossl}://%1.webdevguru.co.uk%{REQUEST_URI} [R=301,L,NE]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.