Creating an admin url for Magento that is admin.ma

2019-03-31 21:21发布

问题:

I'm using some load balanced servers and have a requirement wherein all of my admin tasks are relegated to one server. We have determined that the best way to do this is a DNS entry for admin. to point to our primary server.

The problem I am seeing is that all of the custom admin urls are all still magentostore.com/admin whereas I need admin.magentostore.com.

Any ideas or has anyone done something similar?

Thanks!

回答1:

Try it first in development environment for getting rid of live website issues!

These can be done by the following steps, :

  1. You need to define base url only for admin store view, then after typing /admin in the address string you will be redirected to base url of it. For this purpose you need to set base url configuration option in admin for default values to http://admin.yourdomain.com and for each website you need to specify its own base url (for example http://yourdomain.com). It can be done via admin interface or config.xml file. In the second case, you need to remove all the records from core_config_data table those in these paths: web/secure/base_url and web/unsecure/base_url.

    <config>
         <default>
             <admin>
                 <web>
                     <unsecure> <!-- defining HTTP url options for admin store -->
                         <base_url>http://admin.yourdomain.com/</base_url>
                     </unsecure>
                     <secure> <!-- defining HTTPS url options for admin store -->
                         <base_url>https://admin.yourdomain.com/</base_url>
                     </secure>
                 </web>
             </admin>
         </default>
         <websites>
             <website_code1>
                 <web>
                     <unsecure> <!-- defining HTTP url options for admin store -->
                         <base_url>http://yourdomain1.com/</base_url>
                     </unsecure>
                     <secure> <!-- defining HTTPS url options for admin store -->
                         <base_url>https://yourdomain1.com/</base_url>
                     </secure>
                 </web>
             </website_code1>
             <website_code2>
                 <web>
                     <unsecure> <!-- defining HTTP url options for admin store -->
                         <base_url>http://yourdomain1.com/</base_url>
                     </unsecure>
                     <secure> <!-- defining HTTPS url options for admin store -->
                         <base_url>https://yourdomain1.com/</base_url>
                     </secure>
                 </web>
             </website_code2>
         </websites>
    </config>
    
  2. For automatically applying of admin store view, you need to create .htaccess rule for Magento that will set the store code for running of it to admin and create redirect to /admin/ request path if it is not defined. You need to define rules like these to make it possible:

    SetEnvIf Host ^admin\.yourdomain\.com$ MAGE_RUN_CODE=admin
    RewriteEngine On
    RewriteCond %{HTTP:HOST} ^admin\.yourdomain\.com$
    RewriteCond %{REQUEST_URI} !/admin/
    RewriteRule .* %{REQUEST_URI}index.php/admin/ [R=302,L]
    


回答2:

You need to write an .htaccess rewrite that looks for incoming domains admin.magentostore.com and rewrites it to index.php/admin. If you check the Apache rewrite documentation, you will find plenty of examples of how to achieve it. This isn't actually a Magento question as such, native .htaccess will sort you out.

HTH, JD



回答3:

Go to the menu System > Configuration > Admin > Admin Base URL. There you can enter and enable http://admin.magentostore.com/. You will still need to set the MAGE_RUN_CODE as Ivan suggested to prevent it being used as a normal store.

As an added tweak you can use my (shamelessly plugged) admin rewrite extension to tidy up the URLs. I have been working on another extension to bolster the security by disallowing admin access on non-admin domains, but sadly it is not yet ready for release, watch this space...