So I have the following rule in my htaccess :
RewriteEngine on
RewriteBase /blog/
RewriteRule ^post/ post.php [L]
This gives me access to localhost/blog/post.php
via localhost/blog/post/
Now, when I'm directly typing localhost/blog/post.php
it does not redirect me to localhost/blog/post/
Is there a way to redirect to localhost/blog/post/
in .htaccess or should I do that in php code ?
You need an additional rule to redirect /post.php to /post
RewriteEngine on
RewriteBase /blog/
#1)--redirect /post.php to /post--#
RewriteCond %{THE_REQUEST} /post\.php
RewriteRule ^ /blog/post/ [NC,L,R]
#2)--rewrite /post to /post.php--#
RewriteRule ^post/ post.php [L]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.