How can I remove file extension from a website address?
Just add an .htaccess file to the root folder of your site (for example, /home/domains/domain.example/htdocs/
) with the following content:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
More about how this works in these pages: mod_rewrite guide (introduction, using it), reference documentation
Removing File Extensions from URL
Keep this inside the .htaccess file for removing .html extension from the url.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Removing the file extension from URLs, like .php or .html
Add this line to your .htaccess file:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^\.]+)$ $1.php [NC,L]
Removing file extension AND file name from URL
Seeing as your server uses nginx as a server, and not apache:
i think this should work:
index index.html index.php;
location / {
rewrite ^/(.*)index\.(php|html?)$ /$1 redirect;
}
That should be added to your nginx config
how to remove the url extension
try create .htaccess
file on your root folder then paste this
#remove html file extension-e.g. https://example.com/file.html will become https://example.com/file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
you can read more about this here https://www.plothost.com/kb/how-to-remove-php-html-extensions-with-htaccess/
EDIT
Since you are using Vercel.com, as per their documentation there's a file config named vercel.json
you can add this
{
"cleanUrls": true
}
the docs said,
When set to true, all HTML files and Serverless Functions will have their extension removed. When visiting a path that ends with the extension, a 308 response will redirect the client to the extensionless path.
for more information pls read their docs here https://vercel.com/docs/configuration#project/clean-urls
How to remove .html from URL?
Thanks for your replies. I have already solved my problem. Suppose I have my pages under http://www.yoursite.com/html, the following .htaccess rules apply.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /html/(.*).html\ HTTP/
RewriteRule .* http://localhost/html/%1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /html/(.*)\ HTTP/
RewriteRule .* %1.html [L]
</IfModule>
Related Topics
PHP, Get File Name Without File Extension
Upload Photo to Album With Facebook'S Graph API
Best Solution to Protect PHP Code Without Encryption
How Safe Are PHP Session Variables
How to Create a HTML Table from a PHP Array
Returning Json from PHP to JavaScript
Secure Random Number Generation in PHP
Achieve Hierarchy, Parent/Child Relationship in an Effective and Easy Way
Limit Keyword on MySQL With Prepared Statement
PHP Preg_Match to Find Multiple Occurrences
How to Find the PHP.Ini File Used by the Command Line
How to Extend Access Token Validity Since Offline_Access Deprecation
Laravel 5 Pdoexception Could Not Find Driver
Find Difference Between Two Datetimes and Format At Y-M-D H:I:S