Magento - URL rewriting or redirection issue

2.8k Views Asked by At

I am running a site in Magento version 1.9.1.0 which is SSL enabled. When I open that site's admin panel on a browser either after refresh the cache of browser or in private mode then first time it shows site's homepage rather than admin login page i.e. sitename.com/admin URL redirects to https://sitename.com URL automatically on first time.

Same issue happened when I try to access inner page of the site directly first time.

After this when I enter again URL in browser's address bar as sitename.com/admin then it open admin login page which is good on next time(seems cache works).

I am using Login and Pay with Amazon extension in my Magento site. So when I go for login with Amazon then after inject the credentials it shows me error as follows:

No data received. Unable to load the webpage because the server sent no data on chrome.

secure connection failed on firefox

I am using Base URLs (unsecured and secured as https://sitename.com) in admin panel under System > configuration > General > web which seems to be right? I have doubt in my .htaccess file this part of code. I have used the following code in my .htaccess file:

############################################
## workaround for HTTP authorization
## in CGI environment

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}


RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.sitename.com/$1 [R,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

############################################
## TRACE and TRACK HTTP methods disabled to prevent XSS attacks

RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
RewriteRule .* - [L,R=405]

############################################
## redirect for mobile user agents

#RewriteCond %{REQUEST_URI} !^/mobiledirectoryhere/.*$
#RewriteCond %{HTTP_USER_AGENT}    "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
#RewriteRule ^(.*)$ /mobiledirectoryhere/ [L,R=302]

My Requirements are:

  • Site always open with https which is working fine.

  • When user access the site either with www or without www site always open with https://sitename.com. and avoid index.php in the URL which is working fine.

  • When I access admin panel at any time either first or next to first, it should display admin login screen.

  • Remove error which is occurring after login with Amazon.

Kindly please help me to resolve this issue. If any other code required please let me know.

1

There are 1 best solutions below

1
On BEST ANSWER

I think if you place in .htaccess the following rewrite, it will bypass this Magento stupidity; apache will rewrite it appropriately before Magento get a chance:

RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]