【问题标题】:how to redirect a dynamic URL using .htaccess?如何使用 .htaccess 重定向动态 URL?
【发布时间】:2015-07-08 23:06:53
【问题描述】:

有没有办法重定向这个链接:

http://example.com/?page=profile.php&id=100

http://example.com/profile.php?id=100

使用 htaccess ?? 顺便说一句,我知道我可以从

重定向

http://example.com/?page=profile.php

到:

http://example.com/profile.php

使用 301 重定向

但我在第一个链接中询问id,我将它与& 一起使用,而在第二个URL 中我将它与? 一起使用,有没有办法让重定向考虑到id 参数

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    试试这个:

    RewriteEngine On
    RewriteCond %{QUERY_STRING} ^page=([^&]+)&id=([^&]+) [NC] 
    RewriteRule ^ /%1?id=%2 [NC,R,L]
    

    【讨论】:

    • 实际上,当我将其添加到 .htaccess 文件并调用旧 URL 时,我被重定向到类似 http://example.com/home/account_name/public_html/example.com/profile.php?id=100 这样的地方,因此您可以看到它被重定向并且 ?page 和 @987654325 @sign 已更改,但问题出在路径上。它给了我一条新的道路??为什么要这样做?
    • 非常感谢,现在它工作得非常好,但如果 URL 没有像 ?page=profile.php 这样的 id 参数并且我想将其设为“个人资料”,我希望得到您的建议.php' 如果我添加 301 重定向会与你给我的代码形成对比吗?
    猜你喜欢
    • 1970-01-01
    • 2013-08-29
    • 2015-10-01
    • 2021-06-30
    • 2016-09-18
    • 2021-04-10
    • 1970-01-01
    • 1970-01-01
    • 2013-05-15
    相关资源
    最近更新 更多