做一个重写规则删除扩展名为.php? [英] Making a rewriterule remove .php extension?
问题描述
我想出了一个重写规则来走在我的网站的任何页面,而无需键入的PHP扩展,因为它会自动添加到URL。
I have come up with a rewriterule to to go to any page on my website without typing in the .php extension because it is automatically added to the url.
规则是:重写规则^(\ w +)/ $ /$1.php
The rule is: RewriteRule ^(\w+)/?$ /$1.php
这需要任何你输入我的指标,并增加了.PHP它,这样你就可以把的http:// sampardee。 COM /指数和它拉起来的index.php
It takes anything you type in my index and adds .php to it, so you can put in http://sampardee.com/index and it pulls up index.php
现在我的问题是,如何在用户输入 http://sampardee.com/index.php检测A>并将其更改为 http://sampardee.com/index
Now my question is how to detect when a user enters http://sampardee.com/index.php and change it to http://sampardee.com/index
我怎么能这样做有一个重写规则?
How could I do so with a rewriterule?
推荐答案
您需要强制重定向用户的没有的匹配内部重定向:
You need to force a redirect on the user without matching the internal redirect:
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^(\w+)\.php$ /$1 [R=301]
RewriteRule ^(\w+)/?$ /$1.php
此重定向与 301永久移动
重定向到URL修改用户。
This redirects the user with a 301 Moved Permanently
redirection to the modified URL.
这篇关于做一个重写规则删除扩展名为.php?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!