【问题标题】:.htaccess rewrite url with get parameter.htaccess 用 get 参数重写 url
【发布时间】:2014-05-16 04:38:15
【问题描述】:

这是我第一次尝试 .htaccess

这就是我想要的。

example.com/account/blitzen12 -> example.com/account/index.php?id=10&name=blitzen12

我不想在重写时包含id,可以吗?

Note: id and name which is 10 and blitzen12 is retrive from the database.

到目前为止,这是我尝试过的,但没有成功。

Options +FollowSymLinks  
RewriteEngine On 

RewriteRule ^account/(.*)$ ./account/index.php?page=account&id=$1&name=$2 [L,NC]

html 代码。

<a href="account/index.php?id=10&name=blitzen12">blitzen12</a>

谁能帮我解决这个问题?谢谢。

【问题讨论】:

    标签: php apache .htaccess mod-rewrite


    【解决方案1】:

    “10”或 id 不是 URL 的一部分:

    example.com/account/blitzen12
    

    所以你不能把它改写成另一个 URL,不能凭空抽出来。您要么只需要提供不带“id”的页面(并使用“名称”将其从数据库中拉出),要么将其嵌入到不带查询字符串的 URL 中,例如:

    example.com/account/10/blitzen12
    

    那么您就可以使用以下方法重写它:

    Options +FollowSymLinks  
    RewriteEngine On 
    
    RewriteRule ^account/([0-9]+)/(.*)$ ./account/index.php?page=account&id=$1&name=$2 [L,NC]
    

    【讨论】:

    • 我试过你上面提到的,但没有用。供参考,我将编辑并包含 html..
    • 是否可以重写 html 响应?我不确定它是否称为出站规则?
    • @blitzen12:mod_rewrite 作用于 requests 到达服务器;它与 HTML 没有任何关系。如果您希望 HTML 中的链接 URL 采用特定形式,那么 必须确保它们是该形式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多