1

I have a Magento Installation version 1.9.3.1. Until yesterday It was working fine, but now the frontpage is not working with the error - Too many redirects.

On further checking in the console(firebug), I can see all the files are showing as moved permanently as also it is adding a extra slash / that is two slash in the end of the sitename in the browser address. also in console all the get pages are showing as //

update:

I observed that it is only home-page/index.php where I am facing this issue. for example If I am accessing site/category-name it is working fine.

I tried to fix that using :

if(!$_SERVER['HTTPS'] || strtolower($_SERVER['HTTPS']) != 'on' ){
    header("HTTP/1.1 301 Moved Permanently");
    header('Location: https://' . str_replace('www.','',$_SERVER['HTTP_HOST']) . $_SERVER['REQUEST_URI']);
    exit();
}

but that also didn't worked.

Further Update:

if I use domain.com/index or domain.com/index.php/index I am able to access the site without

too many redirects error

or

moved permanently error

Contents of relevant conf file:

server {
        listen 80;

        server_name www.sub.domain.com;
        #server_name sub.domain.com;
        #rewrite ^(.*) http://sub.domain.com$1 permanent;
}

server {
        listen 80 default;
        listen 443 ssl;
         server_name www.sub.domain.com;
          #ssl        on;
          #ssl_certificate         /key/domain.com.pem;
          #ssl_certificate_key     /key/domain.com.key;

        # access_log off;
        access_log /home/sub.domain.com/logs/access.log;
        # error_log off;
        error_log /home/sub.domain.com/logs/error.log;

        root /home/sub.domain.com/public_html;
        index index.php index.html index.htm;
        server_name sub.domain.com;

        location / {
                try_files $uri $uri/ /index.php?$args;
        }

1 Answer 1

0

I observed that it is only home-page/index.php where I am facing this issue. For example, if I access site/category-name it is working fine.

I cannot say for certain if this is the cause of your redirect issues (there could be something misconfigured elsewhere), but you have four server_name directives (two of which are active doubles of www.sub.domain.com), when you should only need one.

Try this edited .conf file:

#server {
        #listen 80;

        #server_name sub.domain.com www.sub.domain.com;
        #rewrite ^(.*) http://sub.domain.com$1 permanent;
#}

server {
        listen 80 default;
        listen 443 ssl;
        server_name sub.domain.com www.sub.domain.com;
        #ssl        on;
        #ssl_certificate         /key/domain.com.pem;
        #ssl_certificate_key     /key/domain.com.key;

        # access_log off;
        access_log /home/sub.domain.com/logs/access.log;
        # error_log off;
        error_log /home/sub.domain.com/logs/error.log;

        root /home/sub.domain.com/public_html;
        index index.php index.html index.htm;

        location / {
                 try_files $uri $uri/ /index.php?$args;
        }

Notes

A basic rule for nginx is one server_name directive per server block (unlike Apache with ServerName and ServerAlias). This directive can have multiple hostnames specified.

If you want different configurations for a primary domain and a secondary (sub)domain, they should be in separate server blocks e.g.:

server {
        listen 80;

        server_name sub.domain.com;
        # ...other stuff...
}

server {
        listen 80;

        server_name www.sub.domain.com;
        # ...other stuff... 
}

Resources http://nginx.org/en/docs/http/server_names.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .