简体   繁体   中英

Add trailing slash and remove .php extensions

I want to add trailing slash because i have some pages in folder and others not so it looks like:
http://localhost/mysite/about
http://localhost/mysite/gallery/
I want to unify it.
I have already deleted the .php file extension.
But if I try to add a trailing slash, I get a error 500.

My .htaccess file:

RewriteEngine on
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php


How to remove a php file extension and add a trailing slash at the same time?

You need to make the trailing slash optional in your regex pattern. Replace your last line with the following

RewriteRule ^(.*?)/?$ $1.php

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM