简体   繁体   English

添加结尾斜杠并删除.php扩展名

[英]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 / about
http://localhost/mysite/gallery/ http:// localhost / mysite / gallery /
I want to unify it. 我要统一它。
I have already deleted the .php file extension. 我已经删除了.php文件扩展名。
But if I try to add a trailing slash, I get a error 500. 但是,如果尝试添加斜杠,则会出现错误500。

My .htaccess file: 我的.htaccess文件:

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? 如何删除php文件扩展名并同时添加斜杠?

You need to make the trailing slash optional in your regex pattern. 您需要在正则表达式模式中使斜杠为可选。 Replace your last line with the following 将您的最后一行替换为以下内容

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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