【问题标题】:Can someone prompt me in the right direction to use mod_rewrite?有人可以提示我使用 mod_rewrite 的正确方向吗?
【发布时间】:2014-01-17 12:41:44
【问题描述】:

我对此有点陌生,但我正在努力学习。我知道在 PHP 中我们可以有一个以 ?id=something 结尾的 URL,但在我看来,有些网站只是使用正斜杠。这可能使用PHP吗?我看到thesequestions好像说有可能但是我还没破解。

有人可以向我提示mod_rewrite 的正确方向吗?我想更改以下网址

http://www.example.com/all-products/?onsale=true&topic=health&item=adaaos45

进入

http://www.example.com/all-products/items-on-sale/health/adaaos45

你能告诉我正确的方向吗?

【问题讨论】:

    标签: apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    您正在寻找的是 Apache Url Rewriting。

    我将它分解一下以帮助您理解,了解一点regex会有所帮助。

    这里有很多讨论方法的答案,但总结起来,你需要做三件事。

    # Switch on URL Rewriting
    # Choose the URL that you want to display  
    # Point it to the true URL that gives the information.
    
    Options FollowSymLinks
    RewriteEngine On
    
    RewriteRule ^all-products/items-on-sale/health/adaaos45/?$ all-products/?onsale=true&topic=health&item=adaaos45 [NC,L]
    

    当然,如果你想匹配变量的任何结果,你需要匹配正则表达式中的单词,记住它,并在行的最后部分使用它。但这应该让您开始了解正在发生的事情。

    在您的 .htaccess 中使用此代码,浏览到

    http://www.example.com/all-products/items-on-sale/health/adaaos45

    将向您显示此页面上显示的内容。

    http://www.example.com/all-products/?onsale=true&topic=health&item=adaaos45

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-09
      • 1970-01-01
      • 2014-05-25
      • 1970-01-01
      • 1970-01-01
      • 2015-03-06
      • 1970-01-01
      • 2021-03-15
      相关资源
      最近更新 更多