删除扩展名为.php(明确写入)为友好的URL [英] Remove .php extension (explicitly written) for friendly URL

查看:276
本文介绍了删除扩展名为.php(明确写入)为友好的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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供应和URL并不友好。

The home.php is served, and the URL is not friendly.

我怎样才能避免这种情况?我想,如果用户写www.mysite.com/home.php,在URL栏中显示的URL进行www.mysite.com/home~~V

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

推荐答案

您可以从像这样

RewriteCond %{REQUEST_URI} ^/(.*).php$
RewriteRule ^(.*)$ %1 [L,QSA]

这篇关于删除扩展名为.php(明确写入)为友好的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆