1

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?

1 Answer 1

1

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

RewriteRule ^(.*?)/?$ $1.php
Sign up to request clarification or add additional context in comments.

6 Comments

It gives nothing. Still some sites don't have trailing slash and if i type it to the end of URL i got error 500
Do you have any other rules in htaccess?
Try relplacing your secon RewriteCond with RewriteCond %{DOCUMENT_ROOT}/$1.php -f to see what it yields.
It giving error 404 for sites who already don't have trailing slash
It's wired. Are you sure the htaccess you posted here is the htaccess on your server?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.