如何在 php 中制定重写规则?
RewriteEngine on
Rewriterule ^(.*).htm $1.php
当我尝试访问每个 php 页面时,这工作正常
但是如果页面是 about.php ,那么我怎么能使它 RewriteRule ^/somepage $ /somepage.php
(它不起作用),
URL 应该是关于/(目录类型)
RewriteEngine on
Rewriterule ^(.*).htm $1.php
This works fine when i try to access every php page
But how could i make it RewriteRule ^/somepage $ /somepage.php
(its not working )
if the page is about.php the url should be about/ (directory type)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Jan 的答案的另一种选择是:
无论他们是否记得最后的
/
,都会重写它。Alternatively to Jan's answer:
will rewrite it whether they remember the final
/
or not.如果要在 .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:And for arbitrary path segments: