2016-08-24 53 views
1

我有兩個條件:重定向URL以及更改查詢字符串的Apache

http://localhost/restexample/api/con/2/

重寫到

http://localhost/restexample/RestController.php?phone=single&id=2

http://localhost/restexample/api?number=12345

重定向/重寫爲

http://localhost/restexample/RestController.php?phone=all&no=12345

我得到的第一種情況作出適當的反應,但不是在第二種情況下。

我的.htaccess文件是:

# Turn rewrite engine on 
Options +FollowSymlinks 
RewriteEngine on 

# map neat URL to internal URL 
RewriteRule api/con/([0-9]+)/$ "RestController.php?phone=single&id=$1" [nc,qsa] 

RewriteCond %{QUERY_STRING} number=(\d+)$  
RewriteRule "^api" "RestController.php?phone=all&no=%1" [nc,qsa,R=301] 

有人請幫助。

輸出第二個文件:

enter image description here

回答

1

嘗試下列規則:

Options +FollowSymlinks 
RewriteEngine on 

# map neat URL to internal URL 
RewriteRule ^api/con/([0-9]+)/?$ RestController.php?phone=single&id=$1 [NC,L,QSA] 

RewriteCond %{QUERY_STRING} (?:^|&)number=(\d+)$ 
RewriteRule ^api/?$ RestController.php?phone=all&no=%1 [NC,L] 
+0

都能跟得上。相同的錯誤 –

+0

403錯誤。它位於xampp/htdocs/restexample。見圖片。地址欄中的地址。在圖像中顯示 –

+0

URL是'的http://本地主機/ restexample/12345'但這規則是用於'HTTP://本地主機/ restexample/API數= 1234 5' – anubhava

相關問題