【问题标题】:Rewrite rule for same page, multiple variables同一页面,多个变量的重写规则
【发布时间】:2014-09-30 00:40:12
【问题描述】:

我的索引页的 URL 可以包含多个不同的变量,例如:

index.php?page=page1
index.php?page=page2
index.php?page=page3
index.php?page=page4

我将如何使用 .htaccess 来缩短这些 URL,使它们看起来像这样:

index.php/page1
index.php/page2
index.php/page3
index.php/page4

谢谢。

【问题讨论】:

  • 请告诉我们答案是否解决了您的问题。如果是这样,请将问题标记为“已解决”,以帮助其他人!

标签: php .htaccess url url-rewriting


【解决方案1】:

您不需要为此重写规则。 What exactly is PATH_INFO in PHP?

看看$_SERVER['PATH_INFO']

【讨论】:

    【解决方案2】:

    您还可以在 .htaccess 中使用以下代码来生成友好的网址(如果您想了解更多信息,则需要搜索此内容):

    RewriteEngine On
    RewriteRule ^(.*)$ ./index.php?page=$1
    

    这会让你使用

    yourdomain.com/page1 => yourdomain.com/index.php?page=page1
    yourdomain.com/page2 => yourdomain.com/index.php?page=page2
    yourdomain.com/page3 => yourdomain.com/index.php?page=page3
    yourdomain.com/...   => yourdomain.com/index.php?page=...
    

    【讨论】:

      猜你喜欢
      • 2013-10-29
      • 2019-03-19
      • 2018-06-07
      • 2015-09-17
      • 1970-01-01
      • 1970-01-01
      • 2021-09-17
      • 2011-03-12
      • 1970-01-01
      相关资源
      最近更新 更多