我试图做一个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!