【问题标题】:.htaccess - rewriting and then hiding part of the url?.htaccess - 重写然后隐藏部分网址?
【发布时间】:2009-01-26 22:17:45
【问题描述】:

我的 .htaccess 中有以下 RewriteRule:

RewriteRule ^products/([A-Za-z0-9-\s\@]+)/([A-Za-z0-9-\s\@]+)/?$ /store/products/product.php?prod=$1&src=$2 [L,QSA]

它需要一个url,例如:

http://example.com/store/products/lawnmower/blogThatLovesUs

并在此处显示页面:

http://example.com/store/products/product.php?prod=lawnmower&src=blogThatLovesUs

有没有办法可以编辑这个 RewriteRule 以便用户看到

http://example.com/store/products/lawnmower/(sans blogThatLovesUs) 

在他们的地址栏中?

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    当然,您可以这样做,但在此过程中您会丢失您的会员 ID (blogThatLovesUs)。您可以使用原始 URL 进行重定向,然后让生成的页面 (product.php) 在会话中缓存附属值,然后在 PHP 中执行标准重定向(使用 header())到更新的 URL,而不使用附属价值。这有意义吗?

    我想说明的更清楚:

    网址:http://photojojo.com/store/products/lawnmower/blogThatLovesUs

    通过 RewriteRule 你最终得到:

    网址:http://photojojo.com/store/products/product.php?prod=lawnmower&src=blogThatLovesUs

    此时,在 product.php 中,您将 blogThatLovesUs 存储在 session 中的某个位置,然后:

    <?php
        header("Location: http://photojojo.com/store/products/lawnmower/");
    ?>
    

    让浏览器访问您希望它们访问的 URL。

    【讨论】:

    • 工作得很好,谢谢!我只需要通过 jscript 而不是 php 进行重定向,因为我需要首先通过 javascript 在引荐上运行一些谷歌分析。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-17
    • 1970-01-01
    • 2018-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-23
    相关资源
    最近更新 更多