我想在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重定向回域名以避免重复内容: 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文件)......
无法找到解决方案。
编辑: 这似乎有效 - 感谢 Jon Lin !
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]
答案 0 :(得分:0)
首先,我认为你不需要P
标志。由于两个域都指向同一个地方,因此您无需代理请求:
RewriteCond %{HTTP_HOST} ^(www.)?domainB.com$
RewriteRule ^$ /landingpage [L]
对于其他所有内容,您需要捕获请求并将其作为重定向的一部分包含在内:
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !^/landingpage$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?domainB\.com$
RewriteRule ^(.*)$ http://www.domainA.com/$1 [R=301,L]
之前,您正在将所有内容重定向到www.domainA.com
的着陆页
如果您想彻底阻止重定向css和脚本,可以添加其他条件来排除它们:
RewriteCond %{REQUEST_URI} !\.(css|js)$ [NC]
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !^/landingpage$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?domainB\.com$
RewriteRule ^(.*)$ http://www.domainA.com/$1 [R=301,L]