php .htaccess 用 get 参数重写 url
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22853076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.htaccess rewrite url with get parameter
提问by blitzen12
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=&name= [L,NC]
html code.
html代码。
<a href="account/index.php?id=10&name=blitzen12">blitzen12</a>
can anyone help me with this? Thank you.
谁能帮我这个?谢谢你。
回答by Jon Lin
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. 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:
所以你不能把它改写成另一个URL,不能凭空拉出来。您要么只需要提供没有“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=&name= [L,NC]