我有一个非典型服务器设置的客户端,我想更多关注我的代码。
基本上有一些域可以解析为同一主机。其中一个域是SSL,并且有他们的应用程序使用的文件/文件夹。因此,domainOne.com需要被强制使用SSL的www.domainOne.com。然后,www.domainOne.com需要重定向到www.domainTwo.com,不包括所需的文件/文件夹。
之后,只有基本规则才会重定向他们与通配符子域一起挂起的额外域名,不包括已知的子域名。
这是代码的最新版本(等待客户端测试)。
RewriteEngine On
# forces domainOne traffic to HTTPS (www version)
RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{HTTP_HOST} ^domainOne.com
RewriteRule ^(.*)$ https://www.domainOne.com/$1 [R=301,L]
# redirects HTTPS traffic with exceptions to www.domainTwo.com
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{HTTP_HOST} ^www.domainOne.com
RewriteCond %{REQUEST_URI} !^/domainTwo/crash.ashx$
RewriteCond %{REQUEST_URI} !^/domainTwo/reports/bugzScoutFallback.php$
RewriteCond %{REQUEST_URI} !^/ebay/auth/token.php$
RewriteCond %{REQUEST_URI} !^/account/(.*)$
RewriteCond %{REQUEST_URI} !^/admin/(.*)$
RewriteCond %{REQUEST_URI} !^/store/(.*)$
RewriteRule ^(.*)$ http://www.domainTwo.com/$1 [R=301,L]
# redirects extra domains and forces www to domainTwo.com
RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{HTTP_HOST} ^www.domainThree.com [OR]
RewriteCond %{HTTP_HOST} ^domainThree.com [OR]
RewriteCond %{HTTP_HOST} ^mydomainTwo.com [OR]
RewriteCond %{HTTP_HOST} ^www.mydomainTwo.com [OR]
RewriteCond %{HTTP_HOST} ^domainTwo.com
RewriteRule ^(.*)$ http://www.domainTwo.com/$1 [R=301,L]
# excludes known sub-domains and redirects wildcard subdomains to www.domainTwo.com
RewriteCond %{HTTP_HOST} !^support.domainTwo.com
RewriteCond %{HTTP_HOST} !^supplies.domainTwo.com
RewriteCond %{HTTP_HOST} !^blog.domainTwo.com
RewriteCond %{HTTP_HOST} !^www.domainTwo.com
RewriteCond %{HTTP_HOST} ^(.*).domainTwo.com
RewriteRule ^(.*)$ http://www.domainTwo.com/ [R=301,L]
我添加了评论,以帮助理解一切。任何和所有的反馈或建议都表示赞赏。
此版本的代码在SSL上引发了500错误
RewriteEngine On
RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{HTTP_HOST} ^domainOne.com [OR]
RewriteCond %{HTTP_HOST} ^www.domainOne.com [OR]
RewriteCond %{HTTP_HOST} ^www.domainThree.com [OR]
RewriteCond %{HTTP_HOST} ^domainThree.com [OR]
RewriteCond %{HTTP_HOST} ^mydomainTwo.com [OR]
RewriteCond %{HTTP_HOST} ^www.mydomainTwo.com [OR]
RewriteCond %{HTTP_HOST} ^domainTwo.com
RewriteCond %{REQUEST_URI} !^/domainTwo/crash.ashx$
RewriteCond %{REQUEST_URI} !^/domainTwo/reports/bugzScoutFallback.php$
RewriteCond %{REQUEST_URI} !^/ebay/auth/token.php$
RewriteCond %{REQUEST_URI} !^/account/(.*)$
RewriteCond %{REQUEST_URI} !^/admin/(.*)$
RewriteCond %{REQUEST_URI} !^/store/(.*)$
RewriteRule ^(.*)$ http://www.domainTwo.com/$1 [R=301,L]
#Force www and HTTPS for exceptionsite.com exceptions
RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{HTTP_HOST} ^domainOne.com [OR]
RewriteCond %{HTTP_HOST} ^www.domainOne.com
RewriteRule ^(.*)$ https://www.domainOne.com/$1 [R=301,L]
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{HTTP_HOST} ^domainOne.com [OR]
RewriteCond %{HTTP_HOST} ^www.domainOne.com
RewriteCond %{REQUEST_URI} !^/domainTwo/crash.ashx$
RewriteCond %{REQUEST_URI} !^/domainTwo/reports/bugzScoutFallback.php$
RewriteCond %{REQUEST_URI} !^/ebay/auth/token.php$
RewriteCond %{REQUEST_URI} !^/account/(.*)$
RewriteCond %{REQUEST_URI} !^/admin/(.*)$
RewriteCond %{REQUEST_URI} !^/store/(.*)$
RewriteRule ^(.*)$ http://www.domainTwo.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^support.domainTwo.com
RewriteCond %{HTTP_HOST} !^supplies.domainTwo.com
RewriteCond %{HTTP_HOST} !^blog.domainTwo.com
RewriteCond %{HTTP_HOST} !^www.domainTwo.com
RewriteCond %{HTTP_HOST} ^(.*).domainTwo.com
RewriteRule ^(.*)$ http://www.domainTwo.com/ [R=301,L]