when i try login megento using this url http://magento_2_sample.local/admin_n717nk its redirect to below url. please help.
http://magento_2_sample.local/admin_n717nk/http:/index/magento_2_sample.local/admin_n717nk/admin/index/index/key/28a7eb5cc005ed0e48014a4adf0a100313b6e935713e0884afbef77f4dc5f8ad/
We can confirm this happens with domains containing an underscore, as well. The only fix was to remove the underscore that we've found so far.
Replicated this issue on a fresh Magento 2.1.5 installation - originally installed on a subdomain that included an underscore. Admin URL redirected to sub_domain.domain.com/index.php/admin/http:/index/sub_domain.domain.com/index.php/admin/admin/index/index/key/key/
Moving the installation to another subdomain without an underscore resolved the issue.
@rajith44 if you want to report an issue please format this issue according to the Issue reporting guidelines: with steps to reproduce, actual result and expected result.
Please, also identify which version of Magento you are running.
If you are looking for some advice or discussion please refer to the Community Forums or the Magento Stack Exchange site as GitHub issue tracker is intended for technical issues only.

Run this command in the root directory:
`php bin/magento setup:config:set --backend-frontname="magento"
Now open your admin panel with this URL: www.domain.com/magento
Follow this guide to change the Admin URL: Magento 2 Admin URL
`
Was this really closed due to formatting of the issue ?
@sylink, yes, see http://devdocs.magento.com/guides/v2.2/contributor-guide/contributing.html for details:
The Magento 2 development team reviews all issues and contributions submitted by the community of developers in a first-in, first-out basis. During the review we might require clarifications from the contributor. If there is no response from the contributor for two weeks, the issue is closed.
Yes, its probably better to ignore the issue on pedantics than actually take advantage of the free information being given here. Carry on, thanks!
@sylink sorry, I missed your old comment that you was actually able to reproduce issue with similar steps.
Of course if original issue reporter is not able to respond any help with reproduction is appreciated.
https://github.com/magento/magento2/issues/8630#issuecomment-284825468 are you able to reproduce with the same steps on 2.2.0-preview maybe? Will reopen this issue in such case.
I know this is an old thread...
But I have replicated this again today on ver 2.3.0
Removing the underscore from the subdomain fixed the admin redirect issue
This isn't really a problem in the Magento code. Default PHP functionality is used to check if an URL is valid, see:
https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Backend/Model/Url.php#L200
Currently, the check is performed against http://www.faqs.org/rfcs/rfc2396.html .
What Magento could do though, is perhaps add an informative error message should the base_url, configured or detected, contain an underscore.
According to this StackOverflow, Magento could also convert the use of filter_var to parse_url : https://stackoverflow.com/questions/39539468/php-filter-validate-url-not-finding-subdomains-with-underscore
NB There is this bug report for FILTER_VALIDATE_URL: https://bugs.php.net/bug.php?id=64948
PS Interesting: https://stackoverflow.com/a/54670381/1025437
Recently the CAB-forum (*) decided that
All certificates containing an underscore character in any dNSName entry and having a validity period of more than 30 days MUST be revoked prior to January 15, 2019. https://cabforum.org/2018/11/12/ballot-sc-12-sunset-of-underscores-in-dnsnames/
This means that you are no longer allowed to use underscores in domains that will have a ssl/tls certificate.
(*) The Certification Authority Browser Forum (CA/Browser Forum) is a voluntary gathering of leading Certificate Issuers (as defined in Section 2.1(a)(1) and (2) below) and vendors of Internet browser software and other applications that use certificates (Certificate Consumers, as defined in Section 2.1(a)(3) below).
What Magento could do though, is perhaps add an informative error message should the base_url, configured or detected, contain an underscore.
I agree with this. Just wasted a few hours debugging this in Magento 2.3.2 ;-).
Most helpful comment
This isn't really a problem in the Magento code. Default PHP functionality is used to check if an URL is valid, see:
https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Backend/Model/Url.php#L200
Currently, the check is performed against http://www.faqs.org/rfcs/rfc2396.html .
What Magento could do though, is perhaps add an informative error message should the base_url, configured or detected, contain an underscore.
According to this StackOverflow, Magento could also convert the use of filter_var to parse_url : https://stackoverflow.com/questions/39539468/php-filter-validate-url-not-finding-subdomains-with-underscore
NB There is this bug report for FILTER_VALIDATE_URL: https://bugs.php.net/bug.php?id=64948
PS Interesting: https://stackoverflow.com/a/54670381/1025437