簡體   English   中英

如何使用參數對網址進行mod_rewrite

[英]How to do mod_rewrite for a url with parameters

假設我的網站中有以下網址: http://localhost/test/example.php?a = 1&b = 2

如何在.htaccess文件中指定重定向規則,以便在瀏覽器中輸入以下內容時調用此URL: http://localhost/test/example/1.html

換句話說,如果用戶輸入網址: http://localhost/test/example/1.html ,則應該向他顯示以下頁面: http://localhost/test/example.php?a = 1&b = 2

我已經在我的.htaccess文件中嘗試了以下mod_rewrite代碼,但它不起作用:

RewriteRule ^/([^/]+).html /example.php?a=$1&b=$2 [QSA]

這是我的.htaccess文件中的代碼:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([^/]+)/([^/]+)/? /example.php?a=$1&b=$2 [QSA]

注意:我正在使用WAMP2.0,Apache 2.2.6和PHP 5.2.5

它不起作用,因為您的規則中有錯誤,必須在開始處刪除斜杠:

RewriteRule ^test/example/([0-9]+)\.html? /test/example.php?a=$1&b=2 [QSA]

暫無
暫無

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

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