简体   繁体   English

.htaccess使用get参数重写url

[英].htaccess rewrite url with get parameter

this is my first time to try .htaccess 这是我第一次尝试.htaccess

this is what i want. 这就是我要的。

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

i don't want to include the id in rewriting, is it possible? 我不想在重写中包含id,是否可能?

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

so far this is what I've tried but it didn't work. 到目前为止,这是我尝试过的,但它没有用。

Options +FollowSymLinks  
RewriteEngine On 

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

html code. HTML代码。

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

can anyone help me with this? 谁能帮我这个? Thank you. 谢谢。

The "10" or the id, isn't part of the URL: “10”或id不是URL的一部分:

example.com/account/blitzen12

So you can't rewrite it into another URL, can't pull it out of thin air. 所以你不能把它重写成另一个URL,不能凭空而来。 You'll either need to just serve the page without an "id" (and pull it out of the database using the "name") or embed it in the URL without the query string, something like: 您可能需要只提供没有“id”的页面(并使用“name”将其拉出数据库)或将其嵌入URL而不使用查询字符串,例如:

example.com/account/10/blitzen12

then you'd be able to rewrite it using: 然后你就可以使用以下方法重写它:

Options +FollowSymLinks  
RewriteEngine On 

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM