I am trying to remove the php or html’s extension name from the url, but after going through lots of posts on the Internet and tried the methods, but my url does not work as I expected. What I want is xxx.com/xxx/home, instead of xxx.com/xxx/home.php
My system config
- Ubuntu 20.04.1 LTS remote server on aws
Here are the steps I tried so far:
- sudo a2enmod rewrite==>enable module rewrite
- sudo vim apache2.conf==>config the apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
- create a .htaccess file
Options -Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !.php$ [NC]
RewriteCond %{REQUEST_URI} [^/]$
RewriteRule ^(.*)$ $1.php [L]
- put the .htaccess on my diectory (/var/www/html/.htaccess)
Is there any wrong step I made miss any configuration? Could someone help with this issue? Thank you!
2
Answers
Add this in the .htaccess to hide the php file extensions from the url
Try the below code in your
.htaccess
file