代码之家  ›  专栏  ›  技术社区  ›  Rickin Rathatha

重写规则以使php页面由目录url结构加载?

  •  1
  • Rickin Rathatha  · 技术社区  · 7 年前

    我有以下重写规则:

    RewriteEngine On
    RewriteRule    ^test    test.php    [NC,L]  
    

    这允许我通过以下方式访问页面:

    http://www.example.com/test http://www.example.com/test.php 但是我怎样才能防止 http://www.example.com/test.php 无法访问?

    谢谢

    1 回复  |  直到 7 年前
        1
  •  0
  •   Amit Verma    7 年前

    如果要显示403 forbidden error /test.php uri是直接访问的,您可以使用此规则:

    RewriteCond %{THE_REQUEST} /test\.php [NC]
    RewriteRule ^test\.php$ - [R=403,L]
    

    如果要重定向 /测试。php 到新uri /test 使用以下选项:

    RewriteCond %{THE_REQUEST} /test\.php [NC]
    RewriteRule ^test\.php$ /test [L,R]