如何摆脱PHP扩展在.htaccess中 [英] How to get rid of .php extension in .htaccess

查看:218
本文介绍了如何摆脱PHP扩展在.htaccess中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个mod-rewrite在我的的.htaccess 摆脱.PHP的文件扩展名。

I am trying to do a mod-rewrite in my .htaccess to get rid of the ".php" file extension.

因此​​,基本上,这里是我的网站现在: http://www.example.com/about。 PHP

So basically, here is my site right now: http://www.example.com/about.php

下面是我希望它是: http://www.example.com/about

有没有一种方法,使用mod-rewrite在我的.htaccess做到这一点?非常感谢!

Is there a way to do this in my .htaccess using mod-rewrite? Thanks so much!

推荐答案

我想它了!如果你想这个工作了。html的扩展名,应改变的.php到。html的

I figured it out! If you ever want this to work for a ".html" extension, you should change the ".php" to ".html"

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

与行!-d检查它是不是目录,使用-f行会检查所需的文件是一个PHP文件。

The line with !-d checks that it's not a directory, the line with -f checks that the requested file is a .php file.

要,虽然显示这一点,你需要链接到它是这样的:

To display this though, you need to link to it like this:

<a href="http://www.example.com/about"></a>

相反的:

<a href="http://www.example.com/about.php"></a>

由于那么它只会显示的URL作为about.php。

Because then it will just display the URL as about.php.

希望这有助于任何人都希望做到这一点!

Hope this helped anyone looking to do this!

这篇关于如何摆脱PHP扩展在.htaccess中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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