I have 2 website. Let's say website A and B. Both are using Magento.
Almost all of products in B also built-in in A.
Website B is going to be closed hence all of its matching products will be redirected to website A. For other page (non-matching products & other url) will be redirected to A's homepage.
I created script to map matching products from B to A (put it under name mapping.txt), it contains around 20000 url.
To do the redirection, I'm using nginx HttpMapModule (http://wiki.nginx.org/HttpMapModule)
I was able to map it by using this conf:
map $uri $new{
default http://www.a.com/?ref=b;
include /some/path/mapping.txt;
}
server {
listen 80 ;
listen 443 ssl;
server_name www.b.com;
root /some/path/www/b;
#redirect b
rewrite ^ $new redirect;
location / {
index index.html index.php;
try_files $uri $uri/ @handler;
expires 30d;
}
.
.
.
}
The problem is, I want to be able to access B's admin page. Because of the default map, I can not access http://www.b.com/admin
anymore.
Then, I changed the conf:
map $uri $new{
default http://www.a.com/?ref=b;
include /some/path/mapping.txt;
}
server {
listen 80 ;
listen 443 ssl;
server_name www.b.com;
root /some/path/www/b;
location / {
#redirect b
rewrite ^ $new redirect;
index index.html index.php;
try_files $uri $uri/ @handler;
expires 30d;
}
.
.
.
}
By this conf, I still unable to access http://www.b.com/admin
but I can access http://www.b.com/index.php/admin
but the css and js are not loaded because request to ( http://www.b.com/skin/.....
and http://www.b.com/js/.....
are redirected to http://www.a.com/?ref=b
)
But this conf is also problematic, it won't redirect to A's homepage if I type http://www.b.com/index.php/customer/account/login
example content of mapping.txt:
/product-abc.html http://www.a.com/product-abc12.html;
/category-a/product-xyz.html http://www.a.com/product-xyz.html;
/category-b/category-d/product-123.html http://www.a.com/category-e/product-12z.html;
You can use a simple domain redirect on .htaccess for these generic cases...
RewriteCond %{HTTP_HOST} ^www.a.com$ [NC]
RewriteRule ^(.*)$ http://www.b.com/$1 [R=301,L]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.