.htaccess - RewriteRule one single node to another domain -


i want use 1 node in drupal 7 landingpage own domain.

both domains linked same folder, showing same content.

www.domaina.com/landingpage should www.domainb.com - nothing else ...

rewritecond %{http_host} ^(www.)?domaina.com$ rewriterule ^landingpage http://www.domainb.com [r=301,l] 

and want domainb.com show content of domainb.com/landingpage:

rewritecond %{http_host} ^(www.)?domainb.com$ rewriterule ^$ /landingpage [p] 

this works.

now need redirect other pages domainb domaina avoid duplicate content: www.domainb.com/allotherpages should 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] 

alltogether (part of htaccess-file of drupal 7):

<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 custom rule-set:  # rewrite 1 node new domain: rewritecond %{http_host} ^(www.)?domaina.com$ rewriterule ^landingpage http://www.domainb.com [r=301,l]  # front page of domainb shows content of 1 node: rewritecond %{http_host} ^(www.)?domainb.com$ rewriterule ^$ /landingpage [p]  # rewrite other pages domainb.com 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 custom rule-set    <ifmodule mod_headers.c>     # serve gzip compressed css files if exist , 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 exist , client accepts gzip.     rewritecond %{http:accept-encoding} gzip     rewritecond %{request_filename}\.gz -s     rewriterule ^(.*)\.js $1\.js\.gz [qsa]      # serve correct content types, , 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 cache gzipped & non-gzipped css/js files separately.       header append vary accept-encoding     </filesmatch> </ifmodule> </ifmodule> 

"works little bit" – breaks layout , – think, because rewrites else (css-files), ...

can't find solution this.

edit: seems work – 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] 

first, don't think need p flag. since both domains point same place, don't need proxy request:

rewritecond %{http_host} ^(www.)?domainb.com$ rewriterule ^$ /landingpage [l] 

for else, need capture request , include part of redirect:

rewritecond %{request_uri} !^/$ rewritecond %{request_uri} !^/landingpage$ [nc] rewritecond %{http_host} ^(www\.)?domainb\.com$ rewriterule ^(.*)$ http://www.domaina.com/$1 [r=301,l] 

before, redirecting everything landing page of www.domaina.com

if want outright prevent css , scripts being redirected, can add additional conditions exclude them:

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] 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -