0

I would like all my pages for http to redirect to the same location as https

for example

http://www.domain.com/somepage/ now redirects to https://www.domain.com

I would like it to redirect to https://www.domain.com/somepage/

When I applied the rule

return         301 https://$server_name$request_uri;

EDIT:

Adding the header of file

#enter preformatted text here`rackspacedigital.com

    server {

        listen 80;
        listen 443 ssl;

Do I need to separate out the listen to two server blocks?

0
0

Copy file app/code/core/Mage/Core/Controller/Varien/Front.php to app/code/local/Mage/Core/Controller/Varien/Front.php

Modify method protected function _checkBaseUrl($request) from

protected function _checkBaseUrl($request)
    {
        if (!Mage::isInstalled() || $request->getPost() || strtolower($request->getMethod()) == 'post') {
            return;
        }

        $redirectCode = (int)Mage::getStoreConfig('web/url/redirect_to_base');
        if (!$redirectCode) {
            return;
        } elseif ($redirectCode != 301) {
            $redirectCode = 302;
        }

        if ($this->_isAdminFrontNameMatched($request)) {
            return;
        }

        $baseUrl = Mage::getBaseUrl(
            Mage_Core_Model_Store::URL_TYPE_WEB,
            Mage::app()->getStore()->isCurrentlySecure()
        );
        if (!$baseUrl) {
            return;
        }

        $uri = @parse_url($baseUrl);
        $requestUri = $request->getRequestUri() ? $request->getRequestUri() : '/';
        if (isset($uri['scheme']) && $uri['scheme'] != $request->getScheme()
            || isset($uri['host']) && $uri['host'] != $request->getHttpHost()
            || isset($uri['path']) && strpos($requestUri, $uri['path']) === false
        ) {
            Mage::app()->getFrontController()->getResponse()
                ->setRedirect($baseUrl, $redirectCode)
                ->sendResponse();
            exit;
        }
    }


to

protected function _checkBaseUrl($request)
    {
        if (!Mage::isInstalled() || $request->getPost() || strtolower($request->getMethod()) == 'post') {
            return;
        }

        $redirectCode = (int)Mage::getStoreConfig('web/url/redirect_to_base');
        if (!$redirectCode) {
            return;
        } elseif ($redirectCode != 301) {
            $redirectCode = 302;
        }

        if ($this->_isAdminFrontNameMatched($request)) {
            return;
        }

        $baseUrl = Mage::getBaseUrl(
            Mage_Core_Model_Store::URL_TYPE_WEB,
            Mage::app()->getStore()->isCurrentlySecure()
        );
        if (!$baseUrl) {
            return;
        }

        $uri = @parse_url($baseUrl);
        $requestUri = $request->getRequestUri() ? $request->getRequestUri() : '/';
        $newUrl = rtrim($baseUrl, '/') . $requestUri; // PD-April-170
        if (isset($uri['scheme']) && $uri['scheme'] != $request->getScheme()
            || isset($uri['host']) && $uri['host'] != $request->getHttpHost()
            || isset($uri['path']) && strpos($requestUri, $uri['path']) === false
        ) {
            Mage::app()->getFrontController()->getResponse()
                ->setRedirect($newUrl, $redirectCode)
                ->sendResponse();
            exit;
        }
    }


Under system->configuration->web->Url Options , set the flag Auto-redirect to Base URL to Yes.

0

set unsecure base url to https:// and also maybe a problem with Redirect to base url in magento web settings, set to "no".

i hope your config looks like this?

server {
       listen         80;
       server_name    domain.com;
       return         301 https://$server_name$request_uri;
}

server {
       listen         443 ssl;
       server_name    domain.com;
}

https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security
add this in nginx add_header Strict-Transport-Security "max-age=31536000"; in \.php$ location or http {} block.

check headers if it works in either location
https://chrome.google.com/webstore/detail/http-headers/mhbpoeinkhpajikalhfpjjafpfgjnmgk?utm_source=chrome-app-launcher-info-dialog

2
  • Where do I add the "add_header" call? – brentwpeterson Nov 23 '15 at 16:26
  • updated answer . – MagenX Nov 23 '15 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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