2017-05-04 120 views
1

我需要根據我在URL中給出的產品的產品ID重寫URL。例如:如何用動態ID重寫URL

http://localhost/files/eeeee/product_details?pro_id=11 
http://localhost/files/eeeee/product_details/12 

我曾嘗試以下,但它不工作

RewriteCond %{QUERY_STRING} ^pro_id=([0-9]*)$ 
RewriteRule ^product_details\.php$ /product_details/%1? [L] 
+0

通過這個。 http://stackoverflow.com/questions/43468946/rewrite-rule-in-htaccess-convert-query-string-into-slashes-php,http://stackoverflow.com/questions/36815217/replace-url-query-字符串與斜線友好的網址 –

+0

什麼是您的控制器名稱? – ImBS

+0

「'/ files/eeeee/product_details?pro_id = 11'」 - 大概應該是'/files/eeeee/product_details.php?pro_id = 11'?你在你的應用程序中看到了什麼網址?你的代碼片段似乎與你看起來需要的完全相反? – MrWhite

回答

-1

請嘗試:

RedirectMatch ^/product_details.php?pro_id=([0-9]*)$ http://example.site/product_details/$1 

請同時參閱本: apache-query-string-redirects 。由於此解決方案可能需要您將焦點從mod_alias更改爲mod_rewrite。

+0

「from mod_alias to mod_rewrite」 - 'RedirectMatch'是一個mod_alias指令? 'RedirectMatch'也不匹配查詢字符串,它只匹配URL路徑。 – MrWhite

1

您可以簡單地使用這個

RewriteEngine On 
RewriteRule ^/?product_details/(.*?)/?$ /product_details.php?pro_id=$1 [L] 

enter image description here

+0

我已經嘗試過它不重寫URL –

+0

@vimalkumar檢查其顯示'GET'參數的快照。你面臨什麼問題? –

+0

我已將您的代碼放入htaccess中,但其加載到 –