How to add .php extension in htaccess in laravel?

Member

by ryleigh , in category: PHP Frameworks , 5 months ago

How to add .php extension in htaccess in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by dedrick , 5 months ago

@ryleigh 

To add the .php extension to your URLs in Laravel using htaccess, you can create a rewrite rule in your .htaccess file.


Here is an example of how you can add the .php extension to your URLs in Laravel:

  1. Open the .htaccess file in the public folder of your Laravel project.
  2. Add the following rewrite rule at the top of the .htaccess file:
1
2
3
4
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^(.*)$ $1.php [L]
</IfModule>


  1. Save the changes to the .htaccess file.


This rewrite rule will add the .php extension to all URLs in your Laravel application. For example, if you have a route like example.com/about, it will be rewritten as example.com/about.php.


Please note that adding the .php extension to your URLs can affect the normal functionality of your Laravel application and is not recommended unless absolutely necessary.