删除友好 URL 的 .php 扩展名(显式编写) [英] Remove .php extension (explicitly written) for friendly URL
本文介绍了删除友好 URL 的 .php 扩展名(显式编写)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
htaccess 删除我网站文件的 .php 扩展名.
htaccess to remove the .php extension of my site's files.
RewriteEngine on
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ $1.php [L,QSA]
现在,如果我访问我的网站
Now, if I go to my site
www.mysite.com/home
工作正常,它重定向到 home.php 但 URL 仍然友好.
works fine, it redirects to home.php but the URL is still friendly.
但是如果我写这个网址:
But if I write this URL:
www.mysite.com/home.php
服务home.php,网址不友好
The home.php is served, and the URL is not friendly.
我怎样才能避免这种行为?我希望如果用户写的是www.mysite.com/home.php,则在网址栏中显示的网址是www.mysite.com/home
How can I avoid this behavior? I want that if the user writes www.mysite.com/home.php, the URL displayed in the URL bar be www.mysite.com/home
推荐答案
你可以像这样从请求中删除 .php
you can remove .php from requests like so
RewriteCond %{REQUEST_URI} ^/(.*).php$
RewriteRule ^(.*)$ %1 [L,QSA]
这篇关于删除友好 URL 的 .php 扩展名(显式编写)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文