2016-08-30 41 views
1

我試圖在頁面名稱(test2)後面獲取var,但它在php中爲空。

網址:https://example.com/test2/34

的.htaccess:

Options +FollowSymlinks 
RewriteEngine on 

DirectoryIndex index.php 

RewriteRule ^test2 index.php?page=test2&id=$1 [QSA] 

PHP $ _GET vardump

array(2) { ["page"]=> string(5) "test2" ["id"]=> string(0) "" } 

回答

2

這是因爲你不配套和test2/後獲取價值。

您可以使用:

DirectoryIndex index.php 
Options +FollowSymlinks 

RewriteEngine on  

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