如何在php中制定重写规则? [英] How do I make a rewrite rule in php?

查看:85
本文介绍了如何在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,则网址应为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屋!

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