2016-12-31 70 views
-3
多個查詢字符串變量

我在PHP動態網頁,如:網址在PHP重寫使用.htacces

http://www.example.com/page.php?tokenid=1&tokenname=About Us 

我想刪除這部分:查詢字符串

.php?tokenid=1&tokenname=About Us 

頁擴展和顯示網址爲:

http://www.example.com/About Us 

更新:

我試過到目前爲止:

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteBase/

    RewriteCond %{REQUEST_FILENAME}.php -f 
    #RewriteRule ^([a-zA-Z0-9\._-]*)?/(.*)$ $1.php [QSA,E=PATH_INFO:/$2,L] 
    RewriteRule ^([a-zA-Z0-9\._-]*)?/(.*)$ $1.php/$2 [QSA,E=PATH_INFO:/$2,L] 
    RewriteCond %{REQUEST_FILENAME}.php -f 
    RewriteRule ^(.*)$ $1.php [QSA,L] 

    # Fix PHP Authentication with FastCGI mode 
    RewriteCond %{HTTP:Authorization} !'' 
    RewriteRule .*php - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] 
</IfModule> 
+0

你嘗試過什麼嗎? – EhsanT

+0

@EhsanT是的,我已經嘗試了很多谷歌的東西,但acutaully找不到合適的解決方案。 –

+0

所以,如果你已經嘗試過任何東西,當你發佈你的問題,請包括你的代碼(無論你嘗試過) – EhsanT

回答

2

試試這個在您的.htaccess文件:

RewriteEngine on 
RewriteBase/

# Skip actual files/directories 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# If the host matches example.com 
RewriteCond %{HTTP_HOST} ^www\.example\.com$ 
# And the request URI starts with page.php 
RewriteCond %{REQUEST_URI} ^\/page\.php 
# And the querystring matches tokenid=DIGIT&tokenname=TOKEN_NAME 
RewriteCond %{QUERY_STRING} tokenid=\d&tokenname=(.*) 
# Then rewrite the URI to TOKEN_NAME 
RewriteRule ^(.*)$ %1? [L,R] 

你可能想try it online,如果你想。

enter image description here

+0

我已經嘗試了您的建議,但我收到錯誤404頁面,我無法檢索頁面內容。 –

+0

就apache的重寫模塊而言,你正確地重定向到'/ About Us'頁面。您需要確保URI實際存在。添加重寫規則並不奇蹟般地使該頁面可用。 – sepehr

+0

是的,但我從基於tokenid和tokenname的數據庫中獲取頁面,並且我正在重寫url,以便用戶看不到額外的查詢字符串。 –