【问题标题】:Rewriting urls with htaccess and PHP用 htaccess 和 PHP 重写 url
【发布时间】:2013-10-29 17:30:26
【问题描述】:

我的 PHP 页面的原始链接是 page.php?id=70 我想将其重写为 page 请给我一个建议,这是我的 .htaccess 文件中的代码

RewriteEngine On # Turn on the rewriting engine 
RewriteRule   ^[a-zA-Z]+/?$  page.php?id=$1  [L]

【问题讨论】:

  • 请说得更具体一些。谢谢...您当前的 htaccess 将重写 f.e. domain.com/my_page 到 domain.com/?id=my_page;但我猜你想要那里有 ID。
  • 你想从/page.php?id=70重定向到/page
  • 是的,我想从 /page.php?id=70 重定向到 /page

标签: php


【解决方案1】:

这行得通 - 我刚刚测试过。

RewriteRule ^page/$ page.php?id=$1 [NC,L]

在 php 文件中进行此更改后,您的链接在哪里:

<a href="<?=HTTP_PATH?>/page/">Your text</a>

【讨论】:

    【解决方案2】:

    试试:

    RewriteEngine On # Turn on the rewriting engine 
    RewriteRule   ^/page.php?id=([0-9]+)$  /page  [L]
    

    或者,如果您只想从 id=70 重定向,则:

    RewriteEngine On # Turn on the rewriting engine 
    RewriteRule   ^/page.php?id=70$  /page  [L]
    

    【讨论】:

      【解决方案3】:

      最简单的方法永远是最好的,即使人们可以通过键入它们直接访问您的网址,在您的情况下我会使用:

        RewriteRule    ^page/([0-9]+)/?$    page.php?id=$1
      

      这将为您提供以下格式的网址:mydomain.com/page/23/

      干杯

      【讨论】:

      • @Sanjay 您想将 page.php?id=70 重定向到 page-70 或更具体的 page/70/。
      猜你喜欢
      • 1970-01-01
      • 2016-12-05
      • 2012-04-29
      • 2012-08-25
      • 2010-11-04
      • 2023-03-05
      • 2013-06-23
      相关资源
      最近更新 更多