如何在 php 中制定重写规则? [英] How do I make a rewrite rule in php?
本文介绍了如何在 php 中制定重写规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
RewriteEngine on
Rewriterule ^(.*).htm $1.php
当我尝试访问每个 php 页面时这很好用
This works fine when i try to access every php page
但是我怎样才能让它RewriteRule ^/somepage $/somepage.php
(它不起作用)
But how could i make it RewriteRule ^/somepage $ /somepage.php
(its not working )
如果页面是about.php,则url应该是about/(目录类型)
if the page is about.php the url should be about/ (directory type)
推荐答案
如果要在 .htaccess 文件中使用规则,则需要从模式中删除本地路径前缀,因为它在测试模式之前已被删除.如果根目录是 /
.所以试试这个:
If you want to use the rule in a .htaccess file, you need to remove the local path prefix from the pattern as it is removed before testing the pattern. In case of the root directory that is the /
. So try this:
RewriteRule ^somepage/$ /somepage.php
对于任意路径段:
RewriteRule ^([^/]+)/$ /$1.php
这篇关于如何在 php 中制定重写规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文