3

Today i had tried to use the sub domain like admin.domain.com for admin panel by setting the custom url for admin panel in system -> config -> Advanced -> admin -> admin base url -> Custom Admin URL

After changing the url with sub domain. Unable to login admin panel by sub domain. I'm getting too many redirect error. sometimes it going to base domain like www.domain.com. Even after clearing the cache problem still not solved. Anyone help me Regarding this issue, that will be highly appreciated.

Note: I had already tried the solutions on the similar post but nothing will work. And i'm using magento 2.2.6

8
  • you need to create separate virtual host for admin.domain.com , do you have one?
    – MagenX
    Commented Aug 6, 2019 at 20:14
  • yes, i have created a sub domain pointing the magento root folder. virtual host means sub domain right?
    – Ask Xah
    Commented Aug 7, 2019 at 6:47
  • which redirect loop you have then?
    – MagenX
    Commented Aug 7, 2019 at 8:23
  • if i hit sub domain the url path changed to subdomain.domain.com/admin and again it changed to www.domain.com/admin
    – Ask Xah
    Commented Aug 7, 2019 at 8:39
  • you probably have many issues, bug - https://github.com/magento/magento2/issues/12354 or rewrite rule in server config.
    – MagenX
    Commented Aug 7, 2019 at 9:09

4 Answers 4

2

From your question, I am assuming you have set all configurations.
But you haven't set the .htaccess redirection,
Try to set the 301 .htaccess redirection as below.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^admin\.example\.com$
RewriteCond %{REQUEST_URI} !/admin
RewriteRule %{REQUEST_URI}/admin/ [R=301,L]
3
  • It is giving ERR_TOO_MANY_REDIRECTS error.
    – Ask Xah
    Commented Aug 20, 2019 at 11:28
  • whats your subdomain? Commented Aug 20, 2019 at 12:04
  • admin.domain.com is subdomain
    – Ask Xah
    Commented Aug 20, 2019 at 13:22
2

You can set your own custom Magento admin URL in:

Store -> Configuration -> [ADVANCED] -> Admin -> Admin Base URL

Use Custom Admin URL = (YES) Custom Admin URL = https://backend.domain.com

Rules for your .htaccess file to prevent duplicate URLs and redirect directly to admin dashboard:

# rewrite main domain /admin to custom admin backend
RewriteCond %{HTTP:HOST} ^www\.domain\.com$
RewriteCond %{REQUEST_URI} ^/admin
Rewriterule (.*) https://backend.domain.com [R=301,L]

# rewrite any backend domain request that is not /admin to /admin
RewriteCond %{HTTP:HOST} ^backend\.domain\.com$
RewriteCond %{HTTP_COOKIE} !^.*adminhtml.*$ [NC]
RewriteCond %{REQUEST_URI} !/admin/
RewriteRule .* %{REQUEST_URI}index.php/admin/ [R=301,L]
1
  • It is giving ERR_TOO_MANY_REDIRECTS error.
    – Ask Xah
    Commented Aug 20, 2019 at 11:28
1

Usually, when you want a separate Admin Base URL it also means you need an admin instance (which separate with your webserver stacks), and in that case, I suggest you do the following approach:

  • Set your admin URLs as the global (Default store view) config in Config > General > Web (for e.g: admin.example.com)
  • Set your other store URLs in the corresponding Website configurations (e.g US, UK...etc)
  • Check and change the Cookie domain for admin URL instance (Global one) to your wanted sub-domain.
  • Find and fix all issues related to admin base URLs (Magento 2 acknowledge for e.g WYSIWYG media URL)

Magento 2 has the functionality to use separate Admin URL, but unfortunately, based on my own experience it won't help :(

Cheers,

3
  • I agree with this. Admin as separate website on it's entirely own domain may be safest route to go Commented Aug 19, 2019 at 12:19
  • There is an issue on Magento2 for custom admin URL
    – Ask Xah
    Commented Aug 20, 2019 at 11:41
  • @AskBytes this is not the custom admin url Commented Aug 20, 2019 at 11:45
1

If the default config has URLs set as frontend ones, you may experience the problem where the admin subdomain redirects to the frontend domain.

Base URL Note: The base URL for Static View Files and for User Media Files may be different in your setup.

In order not to break the frontend URL, make sure you set up your multi-store URLs in their own store views (Stores > Configuration > General > Web).

The last step is to configure Magento to actually use a subdomain as access to it.

Go to:

Stores > Configuration > Advanced > Admin

Admin Base URL Set the Use Custom Admin URL to Yes and fill in the subdomain.

Note: Make sure your DNS is properly configured for your frontend as well as for the admin subdomain. You could use the same IP for both or separate IP addresses if you plan on using a separate server for it.

Then, clear the cache and try your new setup now, preferably in the incognito tab. (Or you may need a deploy…)

Did it work? If it didn’t, please continue reading.

Cookies In some cases, your cookies might be blocking you from accessing the new subdomain.

Under the default store view, make sure the cookie domain matches your domain. But also make sure you set the proper domain in your website scope.

Is it working? If not, you may need to check your environment setup.

Environment So, here are some questions that could help you.

Have you tried it in the incognito tab? Or flushing the browser cache? Do you have a load balancer? Is the new subdomain flowing through the load balancer? Are you on Nginx? – Check your proxies. Or Apache maybe? – Check your .htaccess files. Are DNS settings ok? Are the domains pointing to the right addresses? Do you get redirected? – Try one of the redirect tracing tools for your browser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.