mod_rewrite 初学者:将文件映射到 php 文件
我正在尝试编写一个简单的规则,以便:
/page
隐式路由到 /page.php
。相反,我希望对 /page.php
的任何直接访问都在地址栏中重定向到 /page
。
目前我有:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
但这不能处理第二种情况。我该如何修改它?
I'm trying to write a simple rule such that:
/page
gets implicitly routed to /page.php
. Inversely, I'd like any direct access to /page.php
to be redirected in the address bar to /page
.
Currently I have:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
But that does not handle the 2nd case. How can I modify it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须先处理第二条规则,然后再处理第一条规则。试试这个:
You have to treat your second rule before your first one. Try this: