I need some help with my Htaccess code.
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule (.*)\.php$ $1 [R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L,QSA]
My Directory Structure is:
Public_Html
css/style.css
img/icon.png
/2/user.php
index.php
create.php
Now the above htaccess code is removing the .php extension from the URL.
Examples
-> example.com/index.php -> example.com/index
-> example.com/2/user.php -> example.com/2/user
Problems with this Htaccess File
I want to hide the index too Example: example.com/index -> example.com
If user types example.com/index.php then he should be redirected to example.com
-
If user type things which do not exist then it should point to example.com
Example:
example.com///*/// -> example.com
When it removes the .php extension then a trailing slash should be added to the end.
Example: example.com/create.php -> example.com/create/
-
If a user wants to access create.php and enter
/create without /
at the end then it should be automatically added.Example:
example.com/create -> example.com/create/
In other words, if after removing .php these both works as same
**Example:** example.com/create = example.com/create/
-
But user should still be able to access the directory
Example:
example.com/2 -> example.com/2/
Here 2 is a folder.
I have some problem with this htaccess script. I searched a lot on Google and Stack Overflow but still can't find any solution.
*This is not a duplicate question. Please check it carefully before marking it as a duplicate. I would be glad if you help me.