# index.php redirect ngnix

**URL:** <https://forum.mautic.org/t/index-php-redirect-ngnix/9987>\
**Category:** General Discussion\
**Created:** [November 27, 2017, 5:38am UTC](https://forum.mautic.org/t/index-php-redirect-ngnix/9987 "2017-11-27T05:38:54Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![harryjwilson](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@harryjwilson](https://forum.mautic.org/u/harryjwilson)\
**Post date:** [November 27, 2017, 5:38am UTC](https://forum.mautic.org/t/index-php-redirect-ngnix/9987/1 "2017-11-27T05:38:54Z")

</div>

Hi all,  
  
  
  
I’m currently encountering a really frustrating issue with Mautic. I have an installation on Ubuntu with Ngnix installed and using serverpilot to manage. The problem I’m facing is when I type the domain, I get 404. When I add index.php to the domain, it works perfectly.  
  
  
  
I have followed all of the advice I can find on this forum in regards to redirects in the .conf file, but to no avail.  
  
  
  
Does anyone have an Ngnix template they could share? or could someone help me with writing a new one. The ones from here and google didn’t work for me.  
  
  
  
Hope you can help!

---

<div class="post-metadata">

**Author:** ![harryjwilson](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@harryjwilson](https://forum.mautic.org/u/harryjwilson)\
**Post date:** [November 27, 2017, 5:38am UTC](https://forum.mautic.org/t/index-php-redirect-ngnix/9987/2 "2017-11-27T05:38:54Z")

</div>

Hi all,

I’m currently encountering a really frustrating issue with Mautic. I have an installation on Ubuntu with Ngnix installed and using serverpilot to manage. The problem I’m facing is when I type the domain, I get 404. When I add index.php to the domain, it works perfectly.

I have followed all of the advice I can find on this forum in regards to redirects in the .conf file, but to no avail.

Does anyone have an Ngnix template they could share? or could someone help me with writing a new one. The ones from here and google didn’t work for me.

Hope you can help!

---

<div class="post-metadata">

**Author:** ![RickBRG](https://avatars.discourse-cdn.com/v4/letter/r/5fc32e/32.png) [@RickBRG](https://forum.mautic.org/u/RickBRG)\
**Post date:** [November 27, 2017, 8:28am UTC](https://forum.mautic.org/t/index-php-redirect-ngnix/9987/3 "2017-11-27T08:28:07Z")

</div>

Hi Harry,

I had the same and was looking for an solution for ages.  
I’m definitely not an expert, but I managed to get rid of that annoying issue by using the following config file (sites-default/default):

[code]##

# You should look at the following URL’s in order to grasp a solid understanding

# of Nginx configuration files in order to fully unleash the power of Nginx.

# [https://www.nginx.com/resources/wiki/start/](https://www.nginx.com/resources/wiki/start/)

# [https://www.nginx.com/resources/wiki/start/topics/tutorials/config\_pitfalls/](https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/)

# [https://wiki.debian.org/Nginx/DirectoryStructure](https://wiki.debian.org/Nginx/DirectoryStructure)

# 

# In most cases, administrators will remove this file from sites-enabled/ and

# leave it as reference inside of sites-available where it will continue to be

# updated by the nginx packaging team.

# 

# This file will automatically load configuration files provided by other

# applications, such as Drupal or Wordpress. These applications will be made

# available underneath a path with that package name, such as /drupal8.

# 

# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.

## 

server {  
listen 443 ssl;  
root /var/www/mautic;

##### Mautic Specific

```
   # For any inbound request to the mautic directory try using mautic index.php to handle the requests before you give up.
   location / {
      try_files $uri /var/www/mautic/;
   }

    # For any inbound requests that have non-exisiting files with these extentions:
    # Try passing the request to mautic before you give up and throw a 404.
    # This is particularly important in order to get paths like this to work correctly:
    # https://host.domain.tld/mautic/form/generate.js?id=1 (If you look at the Mautic code there is a public route
    # - mautic_form_generateform - that handles the creation of this "file".)
    # Normally files like this would be handled by nginx as "physical files", but in this case we want nginx to
    # check with mautic to see if it has what the request is looking for.)
    location ~ /mautic/(.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)){
        # .gif and .js files here are not showing up.
        try_files $uri $uri/ /mautic/index.php?$args;
    }
    ##### End Mautic ###########

   location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }

    location ~ /.ht {
        deny all;
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

   # error_page 500 502 503 504 /50x.html;
       location = /50x.html {
    }

    location ~ [^/].php(/|$) {
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }
        fastcgi_index index.php;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # same path as above
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+?.php)(/.*)$;
        include /etc/nginx/fastcgi_params;
    }

```

}

server{  
listen 80;  
return 301 https://%%%domainurl%%%$request\_uri;  
}  
[/code]

Please note that this is only working if you enabled SSL on your nginx config. I do not know if this code is safe, corrupt or not good at all. I just used it and it worked.

Also dont forget to change the ‘%%%domainurl%%%’ to your domain (or subdomain) and to change the dir of the root url.

Have a nice day!

Rick

---

<div class="post-metadata">

**Author:** ![harryjwilson](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@harryjwilson](https://forum.mautic.org/u/harryjwilson)\
**Post date:** [November 27, 2017, 10:44pm UTC](https://forum.mautic.org/t/index-php-redirect-ngnix/9987/4 "2017-11-27T22:44:45Z")

</div>

Hi Rick,

Sadly this didn’t work for me even with SSL. I do not have a site-available folder in my server. Do you think server pilot may have removed it? Pulling my hair out here…!

---

<div class="post-metadata">

**Author:** ![harryjwilson](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@harryjwilson](https://forum.mautic.org/u/harryjwilson)\
**Post date:** [November 29, 2017, 10:56pm UTC](https://forum.mautic.org/t/index-php-redirect-ngnix/9987/5 "2017-11-29T22:56:46Z")

</div>

Bump… Can anyone help with this? 🙂

---

<div class="post-metadata">

**Author:** ![harryjwilson](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@harryjwilson](https://forum.mautic.org/u/harryjwilson)\
**Post date:** [December 12, 2017, 12:06am UTC](https://forum.mautic.org/t/index-php-redirect-ngnix/9987/6 "2017-12-12T00:06:49Z")

</div>

Can anyone help?

---

<div class="post-metadata">

**Author:** ![bizcrony](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/bizcrony/32/409_2.png) [@bizcrony](https://forum.mautic.org/u/bizcrony)\
**Post date:** [December 12, 2017, 1:24pm UTC](https://forum.mautic.org/t/index-php-redirect-ngnix/9987/7 "2017-12-12T13:24:33Z")

</div>

@harryjwilson it seems a permission issue . how i can check it out ?

---

<div class="post-metadata">

**Author:** ![ninjoan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ninjoan/32/1005_2.png) [@ninjoan](https://forum.mautic.org/u/ninjoan)\
**Post date:** [December 12, 2017, 1:40pm UTC](https://forum.mautic.org/t/index-php-redirect-ngnix/9987/8 "2017-12-12T13:40:41Z")

</div>

@harryjwilson you are missing a module or extension in your server is called `a2enmod rewrite`

---

<div class="post-metadata">

**Author:** ![bizcrony](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/bizcrony/32/409_2.png) [@bizcrony](https://forum.mautic.org/u/bizcrony)\
**Post date:** [December 12, 2017, 1:53pm UTC](https://forum.mautic.org/t/index-php-redirect-ngnix/9987/9 "2017-12-12T13:53:32Z")

</div>

@ninjoan you mean PHP extention?

---

<div class="post-metadata">

**Author:** ![ninjoan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ninjoan/32/1005_2.png) [@ninjoan](https://forum.mautic.org/u/ninjoan)\
**Post date:** [December 12, 2017, 1:56pm UTC](https://forum.mautic.org/t/index-php-redirect-ngnix/9987/10 "2017-12-12T13:56:29Z")

</div>

yes is called extension

---

<div class="post-metadata">

**Author:** ![bizcrony](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/bizcrony/32/409_2.png) [@bizcrony](https://forum.mautic.org/u/bizcrony)\
**Post date:** [December 12, 2017, 1:57pm UTC](https://forum.mautic.org/t/index-php-redirect-ngnix/9987/11 "2017-12-12T13:57:16Z")

</div>

@ninjoan indeed
