【问题标题】:.htaccess and PHP profile system [duplicate].htaccess 和 PHP 配置文件系统 [重复]
【发布时间】:2011-07-03 13:53:58
【问题描述】:

可能重复:
htaccess rewrite for query string

在网址中,要查看某人的个人资料,现在,您转到:

http://{url here}/profile/?url={profile url}

我的问题是,我该怎么做:

http://{url here}/profile/{profile url}

这可能吗?

【问题讨论】:

    标签: php .htaccess rewrite profile


    【解决方案1】:

    是的,可以使用 .htaccess,这是一个入门教程(查看第 4 个示例):

    http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html

    【讨论】:

    • 我看过这个教程,但在 htaccess 方面我是个菜鸟。谢谢你。非常,这正是我需要知道的。
    • RewriteEngine On RewriteRule ^/profile/([a-zA-Z0-9_-]+)$ user.php?url=$1 RewriteRule ^/profile/([a-zA-Z0-9_-]+)/$ user.php?url=$1
    【解决方案2】:

    假设您已安装 mod_rewrite,这是您的 .htaccess 文件中的一条简单规则。

    RewriteRule /profile/([A-Za-z]+)$    /profile?url=$1
    

    该规则假定您的 {profile url} 变量将始终仅由字符组成。

    如果您还没有此功能,这里有一个很好的 article@ 设置此功能(即 mod_rewrite)。

    【讨论】:

      【解决方案3】:

      您正在寻找的是一个重写引擎。假设您最有可能使用 Apache,因为您提到了 .htaccess 文件,那么您很幸运,因为 Apache 可以为您完成这项工作。您将使用 Apache 的 mod_rewritemod_alias 扩展来完成工作。

      http://www.doriat.com/mod_rewrite6.html 有一个专门针对 PHP 使用 mod_rewrite 的教程,但您可能会发现 Apache 自己网站上的示例更有帮助。 http://martinmelin.se/rewrite-rule-tester/ 将让您在编写重写规则时对其进行测试,以消除等式中的一些挫败感。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-06-22
        • 1970-01-01
        • 2021-09-24
        • 2016-02-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-04-02
        相关资源
        最近更新 更多