How do I make a rewrite rule in php?

拥有回忆 提交于 2019-12-17 21:18:29

问题


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)


回答1:


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

And for arbitrary path segments:

RewriteRule ^([^/]+)/$ /$1.php



回答2:


Alternatively to Jan's answer:

RewriteRule ^/about/?$ /about.php

will rewrite it whether they remember the final / or not.




回答3:


RewriteRule ^/about/$ /about.php


来源:https://stackoverflow.com/questions/2506148/how-do-i-make-a-rewrite-rule-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!