Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6604711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:11:36+00:00 2026-05-25T19:11:36+00:00

At work we are switching from a shared LAMP stack to a VPS running

  • 0

At work we are switching from a shared LAMP stack to a VPS running nginx. I’m significantly more comfortable with Apache but learning to use Nginx has been pretty exciting (or as exciting as learning to configure a new webserver can be.

The current issue is this: on several domains we need to remove index.php from the URL for canonicalization. This is the last thing that we currently need to take care of for these domains.

I’ve been researching plenty of different techniques for removing index.php from a URL (most of which are specifically for CI or ExpressionEngine) and I’ve tried to adapt several of these for personal use but I end up with an infinite loop error which I can only imagine is related to the following:

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

I’m hell-bent on learning how all of this works but right now I need to ask for help figuring this out so that we can move forward and I can figure out what it is that I’m doing wrong.

I would greatly appreciate any responses and will further appreciate anyone who is willing to go a little in-depth on the subject to help someone new like myself and anyone else who might be in a similar situation that reads this.

Thank you!

UPDATE
To make things easier I’m just going to put my nginx config up here for this vhost.

server  {
    listen          80;
    server_name     examplesite.com;
    # redirect non-www to www. for canonical urls
    rewrite ^/(.*) http://www.examplesite.com/$1 permanent; 
}

server {
    listen          80;
    server_name     www.examplesite.com;

    error_log   /srv/http/nginx/examplesite.com/log/nginx-error.log;
    access_log  /srv/http/nginx/examplesite.com/log/nginx-access.log;

    root  /srv/http/nginx/examplesite.com/root;

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

    location ~ \.php$ {
        include        fastcgi.conf;
        fastcgi_param  PHP_ADMIN_VALUE "error_log=/srv/http/nginx/examplesite.com/log/php-error.log";
        fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
    }

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:11:37+00:00Added an answer on May 25, 2026 at 7:11 pm

    Try this …

    server  {
        listen          80;
        server_name     examplesite.com;
        # redirect non-www to www. for canonical urls
        # proper way to do this
        rewrite ^ http://www.examplesite.com$request_uri? permanent; 
    }
    
    server {
        listen          80;
        server_name     www.examplesite.com;
    
        error_log   /srv/http/nginx/examplesite.com/log/nginx-error.log;
        access_log  /srv/http/nginx/examplesite.com/log/nginx-access.log;
    
        root  /srv/http/nginx/examplesite.com/root;
    
        # add index under server as you have done for root
        index index.php index.html;
    
        location / {
            # drop the "=404". Nginx will return 404 by itself if not found.
            # note the "last" should not be added to "try_files"
            # whether you need something after "$uri/" depends on your setup.
            # this should do for most unless running WP etc
            try_files $uri $uri/;
        }
    
        location ~ \.php$ {
            # Return '400 Bad Request' for malformed URLs
            # See: http://wiki.nginx.org/Pitfalls#Pass_Non-PHP_Requests_to_PHP.
            location ~ \..*/.*\.php$ {
                return 400;
            }
    
            # Rewrite "index.php" requests
            rewrite ^(.*)index.php(.*)$ $1$2    permanent;
    
            # continue for other php and rewritten "index.php" requests 
            include        fastcgi.conf;
            fastcgi_param  PHP_ADMIN_VALUE "error_log=/srv/http/nginx/examplesite.com/log/php-error.log";
            fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
        }
    
        ...
    
    
    }
    

    Not 100% about the index.php rewrite line as there is a chance it might put you in a redirect loop. If that is the case, then the answer is to just serve the index.php requests but change all links in the application to remove them so that they disappear over time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For my school work, I do a lot of switching computers (from labs to
I imported external libraries using absolute path. But I have two work environments, switching
I'm interested in switching from Capistrano to Chef, but am having a few issues
I work with C# at work but dislike how with webforms it spews out
We are switching from a non-clustered to a 2-node clustered MSMQ Windows Server 2008
I am just switching from C to C# and would like to invest sometime
I'm switching from WAMP to XAMPP and XAMPP has broken my vhosts. It won't
This post is a duplicate from superuser.com, but since I had no answers, I
I am trying to understand the behavior of view controllers when switching from one
We're switching our MVC3 application from IIS 6 to 7.5. I'm working on setting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.