【问题标题】:Apache mod rewrite url htaccessApache mod 重写 url htaccess
【发布时间】:2013-05-09 16:15:00
【问题描述】:

我有点困惑,还在学习如何在 Apache htaccess 中重写

我该如何转这个:

http://www.mydomain.com/dir1/post.php?%20id=1

进入这个:

http://www.mydomain.com/category1/post/1

这是我的参考,我不确定我是否正确

<a href='http://www.mydomain.com/dir1/post.php? id=$id'>

【问题讨论】:

    标签: apache url rewrite


    【解决方案1】:

    如果你只需要重写一个 URL,你可以使用一个简单的重写规则。

    RewriteRule ^dir1/post.php?%20id=1 category1/post/1 [L]
    

    或者您可能需要将 %20 替换为空白字符正则表达式

    RewriteRule ^dir1/post.php?[\s]id=1 category1/post/1 [L]
    

    您需要确保 mod_rewrite 也已打开(.htaccess 中的“RewriteEngine On”)。

    这是一个很好的 tut:http://coding.smashingmagazine.com/2011/11/02/introduction-to-url-rewriting/

    【讨论】:

    • 非常感谢您的帮助先生,我会尝试您对我的建议...抱歉英语不好...感谢您的帮助..上帝保佑
    • 嗨..amm 再次我想问一下文件.htaccess [在我的情况下它位于/public_html] 的位置是否对其效果有影响?我所做的是这个.. RewriteEngine on RewriteRule ^dir1/post.php?%20id=1 category1/post/1 [L]
    • 尝试将 %20 替换为 [\s]。这是空白字符的正则表达式。如果这不起作用,请尝试here 的建议。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 2012-02-27
    • 1970-01-01
    • 1970-01-01
    • 2011-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多