Removing .php with NGINX in ISP Config

Discussion in 'General' started by mattdavison, Nov 25, 2022.

  1. mattdavison

    mattdavison New Member

    Hello!
    After many many attempts at achieving this I did have some luck editing the .vhost file for the individual website, however this suddenly resets at random times which isn't particularly reliable.
    I would like to remove the .php extensions on my URLs for my website mjdws.com, however I don't want it to affect all websites as each one has individual needs which vary.
    How would I go about adding a working piece of NGINX code to the site to make this work?
    Examples preferred : )
    Thanks in advance!
     
  2. Th0m

    Th0m ISPConfig Developer Staff Member ISPConfig Developer

    It doesn't randomly reset, this happens because ISPConfig builds the vhost from a master template. Add custom config in ISPConfig, through the Options tab, as nginx directive.
     
  3. mattdavison

    mattdavison New Member

    When putting it in as an NGINX directive it bugs and downloads each page as an NGINX file instead - can you suggest an NGINX snippet that would work successfully? And how come after changing the vhost ISP Conf will reset it?
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    Then you entered a wrong Nginx snippet. What you enter depends on the cms you use, as you neither provide such information nor the snippet that you use which does not work, it#s not easy to help you.

    How shall ISPConfig be able to manage your server if you don't want to allow it to change the config files it manages?
     
    Th0m likes this.
  5. mattdavison

    mattdavison New Member

    Hi!
    I tried to use
    Code:
    location / {
        try_files $uri $uri.html $uri/ @extensionless-php;
        index index.html index.htm index.php;
    }
    
    location ~ \.php$ {
        try_files $uri =404;
    }
    
    location @extensionless-php {
        rewrite ^(.*)$ $1.php last;
    }
    
    But it fails to work despite working if pasted into the vhost, any ideas?
     
  6. Th0m

    Th0m ISPConfig Developer Staff Member ISPConfig Developer

    Maybe have a little patience? And why ask one person directly?
    - This is a forum where everyone can help each other out and share knowledge, not a support channel to get help from one specific person
    - You posted just a little over 24 hours ago, in a weekend. Why expect a reply right away when you are asking something in a public space?

    Also, Till clearly stated that more info would be welcome in #4, but you still do not provide which CMS you are using.

    This is just rude.
     
    tal56 and ahrasis like this.
  7. mattdavison

    mattdavison New Member

    I think it’s quite clear that this was not intended to be rude.

    I am not using a CMS - I have built the website with PHP and I’m hosting it on ISP Config on Digital Ocean using NGINX.

    I hope this now makes more sense.
     
  8. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    It doesn't actually. If you did write your own code, why you need to code its file with php extension at all?

    I can google where you get the code to remove file with php extension as well as anybody else but we cannot assume anything unless we have all the relevant facts disclosed.

    Any forum rules will say not to bump within 24 hours unless you are familiar with any forum at all. If you wish to have much better support, then subscribe and post in specific board for subscribers as in there you will have faster response. Otherwise, pay respect to each and every members that are trying to help freely as I do agree with @Th0m.
     
  9. mattdavison

    mattdavison New Member

    I’m unsure what you mean in that first paragraph suggesting that I do not code the file with the PHP extension? Without an extension a file will not work as intended and will revert to acting as a plain text file. For this reason I want to clean the URLs up and instead of having something such as example.com/about.php I’d prefer to have example.com/about. This means the files can remain as .PHP but the server can interpret it the same without the .PHP extension being present.

    This seems to work everywhere else I’m aware of but faces errors when pasted into the NGINX directives on ISP Config. I have googled it and I’m not able to find any alternatives.

    Hoping that maybe someone on this forum has had a similar experience or has some more experience and would be able to give me some guidance as to what I am doing incorrectly so that I can resolve the issue I’m facing.
     
  10. Th0m

    Th0m ISPConfig Developer Staff Member ISPConfig Developer

    I do not use nginx myself, but I have seen the extension being "hidden" before on ISPConfig systems with such nginx snippets. Maybe try something else by searching around online?
     
  11. till

    till Super Moderator Staff Member ISPConfig Developer

    ISPConfig does nothing else than insert the exact code from the Nginx directives field into the host. It might be that something else is wrong in the config of that site which makes nginx reject it or you did other things besides inserting that snippet in the vhost like removing config etc. Check nginx sites-available folder if there is a vhost file with .err ending and use debug mode: https://www.faqforge.com/linux/debugging-ispconfig-3-server-actions-in-case-of-a-failure/
     

Share This Page