Removing the file extensions from web pages or resources can make your URL look cleaner and more user-friendly, as well as prevent some security issues.
If you want to remove the file extensions, such as .php
or .html
, from your URL, you can do this by using either the .htaccess or NGINX configuration files.
Using .htaccess
The .htaccess is a configuration file that allows you to override some of the server settings on a per-directory basis.
You can use .htaccess to remove the file extensions from your URL by using the RewriteEngine module, which allows you to rewrite the URL based on certain conditions and rules.
To use htaccess to remove the file extensions from your URL, follow these steps:
- Log in to your RunCloud dashboard and open the web application settings. In the left menu, click on the “File Manager” to create and edit existing files.
- Navigate to the directory where the public files for your web application is located.
- Create or edit the existing .htaccess file by using the RunCloud text editor.
- Add the following code to the .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
This code will remove the .php extension from your URL by checking if the requested file exists, and if it does, it will then rewrite the URL without the extension.
- Save and exit the .htaccess file. Test your URL by accessing it from your browser. You should see that the .php extension is gone.
Note: You can also use this method to remove other file extensions, such as .html
, by changing the .php
to .html
in the code.
Using NGINX
NGINX is a front-end web server that handles incoming requests from clients, and then serves the static content, such as images, CSS, JS, etc.
You can use NGINX to remove the file extensions from your URL by using the location directive, which allows you to define how NGINX should process requests for different locations or paths.
To use NGINX to remove the file extensions from your URL, follow these steps:
- Log in to your RunCloud dashboard and select the server that has NGINX installed.
- Click on Web Application from the main navigation menu and then click on the web application that you want to edit.
- Click on NGINX Config from the sub-navigation menu and then click on Add a New Config.
- Choose
location.main
as the type of config and enter any name for your config file. - Add the following code to the config file:
location ~ \.php$ { try_files $uri =404; }
location @extensionless-php { rewrite ^(.*)$ $1.php last; }
location ~ \.html$ { try_files $uri =404; }
location @extensionless-html { rewrite ^(.*)$ $1.html last; }
Save and close your Nginx config.
That’s it! Your URL structure should be updated.