htaccess的重写URL以get参数 [英] .htaccess rewrite url with get parameter

查看:511
本文介绍了htaccess的重写URL以get参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次尝试的.htaccess

this is my first time to try .htaccess

这就是我想要的。

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

我不希望包括ID的重写,这可能吗?

i don't want to include the id in rewriting, is it possible?

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 code.

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

谁能帮助我?谢谢你。

can anyone help me with this? Thank you.

推荐答案

在10或ID,是不是URL的一部分:

The "10" or the id, isn't part of the URL:

example.com/account/blitzen12

所以你不能把它改写成另一个URL,不能把它凭空。你要么需要只是提供页面没有身份证(将其拉出使用名的数据库),而不查询字符串的URL或嵌入,是这样的:

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:

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]

这篇关于htaccess的重写URL以get参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆