我想将 Drupal 7 中的一个节点用作具有自己域的登录页面。
两个域都链接到同一个文件夹,显示相同的内容。
www.domainA.com/landingpage应该是www.domainB.com - 没有别的......
RewriteCond %{HTTP_HOST} ^(www.)?domainA.com$
RewriteRule ^landingpage http://www.domainB.com [R=301,L]
我希望domainB.com显示 domainB.com/landingpage 的内容:
RewriteCond %{HTTP_HOST} ^(www.)?domainB.com$
RewriteRule ^$ /landingpage [P]
这行得通。
现在我需要将所有其他页面从 domainB 重定向回 domainA 以避免重复内容: www.domainB.com/allotherpages应该是www.domainA.com/allotherpages
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_URI} !^/landingpage$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?domainB\.com$
RewriteRule ^ http://www.domainA.com [R=301,L]
总而言之(Drupal 7 的 htaccess 文件的一部分):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^ - [E=protossl]
RewriteCond %{HTTPS} on
RewriteRule ^ - [E=protossl:s]
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule "(^|/)\." - [F]
RewriteBase /
# HERE STARTS MY CUSTOM RULE-SET:
# Rewrite one node to new Domain:
RewriteCond %{HTTP_HOST} ^(www.)?domainA.com$
RewriteRule ^landingpage http://www.domainB.com [R=301,L]
# Front page of domainB shows content of one node:
RewriteCond %{HTTP_HOST} ^(www.)?domainB.com$
RewriteRule ^$ /landingpage [P]
# Rewrite all other pages from domainB.com to main domainA.com:
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_URI} !^/landingpage$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?domainB\.com$
RewriteRule ^ http://www.domainA.com [R=301,L]
# HERE ENDS MY CUSTOM RULE-SET
<IfModule mod_headers.c>
# Serve gzip compressed CSS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.css $1\.css\.gz [QSA]
# Serve gzip compressed JS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.js $1\.js\.gz [QSA]
# Serve correct content types, and prevent mod_deflate double gzip.
RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]
<FilesMatch "(\.js\.gz|\.css\.gz)$">
# Serve correct encoding type.
Header set Content-Encoding gzip
# Force proxies to cache gzipped & non-gzipped css/js files separately.
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>
</IfModule>
“工作一点点”——但打破了布局和一切——我认为,因为它也重写了其他所有东西(CSS文件)......
找不到解决方案。
编辑:这似乎可行——感谢乔恩林!
RewriteCond %{HTTP_HOST} ^(www.)?domainA\.com$
RewriteRule ^landingpage http://www.domainB.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^(www.)?www.domainB\.de$
RewriteRule ^$ /landingpage [P]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_URI} !\.(css|js|png|svg|ico|jpg)$ [NC]
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !^/landingpage$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?www.domainB\.de$
RewriteRule ^(.*)$ http://www.domainA.com/$1 [R=301,L]