簡體   English   中英

.htaccess使用get參數重寫url

[英].htaccess rewrite url with get parameter

這是我第一次嘗試.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>

誰能幫我這個? 謝謝。

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

example.com/account/blitzen12

所以你不能把它重寫成另一個URL,不能憑空而來。 您可能需要只提供沒有“id”的頁面(並使用“name”將其拉出數據庫)或將其嵌入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]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM