I am trying to remove .php extension for only pages under a subcategory folder of the website.
currently: example.com/blog/my-first-blog.php
what i want: example.com/blog/my-first-blog/
I have tried the following rule in .htaccess (placed in root) but it still shows .php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/blog/$1.php -f
RewriteRule ^(.+?)/?$ /blog/$1.php [L]
4
Answers
I figured it out I just had to create .htaccess file under the "/guide/" directory. with the following rule note
RewriteBase /guide/
for making sure it only removes .php under "/blog/" folderThe best way to achieve result you want is building a routing.
Firstable, you need to rewrite all traffic to your index.php:
Then, you need to write router that will be parsing URL paths.
The simplest example of router is:
You can check how does it work in
PHP
frameworks to get a better solution, or use one of them.Try this —
Try this