简体   繁体   中英

htaccess redirect subdomain to domain magento store


There is a shop on Magento - site.com. There's also a store views on subdomains, such sub1.site.com, sub2.site.com, sub3.site.com. Everything works fine but the theme set by bit does not work on subdomains. Theme uses Mage :: getUrl () to generate the URLs for the AJAX Quick View and Add to Cart. It uses the store's base URL.
From the main site site.com everything works fine, preview AJAX works. On subdomains is not working because base URL to form subdomains sub1.site.com/catalog/ajax_product/view, but must be of the form site.com / catalog / ajax_product / view. Redirection in. Htaccess on a subdomain like:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(catalog/ajax_product/.*|checkout/cart/add/.*)$
RewriteRule ^(.*)$ http://site.com/$1/ [R=301,L]

Does not work!

Help!

I'm not sure if your application configuration is correct. In my opinion you don't need to make redirection with .htaccess . So here are couple of checkpoints:

1) Check that you have set a correct Base secure and unsecure URLs in Back Office (Admin Panel) for each store view (subdomain)

System > Configuration > Web > (Un)secure > Base Url

By default there should be http://store.com , and for each website (regarding Magento scope) URL should be different.

2) Cookie domain must be set for each store view respectively.

System > Configuration > Web > Session Cookie Management > Cookie Domain

For the default store you can leave it empty, but you must fill it for others, eg .sub1.store.com , .sub2.store.com , etc. Note that dot ('.') at the beginning is mandatory.

3) Set Apache vhosts for each domain.

You should have separate entries for site.com , sub1.site.com , etc in your vhosts configuration.

Now you can define which store view to load based on the domain. You can do this in 3 ways:

  • .htaccess
  • modify index.php of application
  • set proper Env variable directly in vhost

In this post you can find each mentioned solution.

While dealing with multiple store views and domains with Magento it is all about to load a proper store code in Mage::run() method.

Here's an example for .htaccess solution:

SetEnvIf Host .*sub1.site.com.* MAGE_RUN_CODE="sub1"
SetEnvIf Host .*sub2.site.com.* MAGE_RUN_CODE="sub2"

Don't forget to flush cache and perform reindex of all entities after you set is all correct.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM