How do I make a rewrite rule in php?

后端 未结 3 1115
粉色の甜心
粉色の甜心 2020-12-12 07:22
RewriteEngine on
Rewriterule ^(.*).htm $1.php

This works fine when i try to access every php page

But how could i make it RewriteRule

相关标签:
3条回答
  • 2020-12-12 07:48
    RewriteRule ^/about/$ /about.php
    
    0 讨论(0)
  • 2020-12-12 08:02

    Alternatively to Jan's answer:

    RewriteRule ^/about/?$ /about.php
    

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

    0 讨论(0)
  • 2020-12-12 08:14

    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
    
    0 讨论(0)
提交回复
热议问题