0

我想将 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]
4

1 回答 1

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]
于 2013-10-07T15:36:12.590 回答