.htaccess 如何用动态ID重写URL

.htaccess 如何用动态ID重写URL,.htaccess,codeigniter,url,url-rewriting,.htaccess,Codeigniter,Url,Url Rewriting,我需要根据我在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

我需要根据我在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]
请尝试:

RedirectMatch ^/product_details.php?pro_id=([0-9]*)$  http://example.site/product_details/$1
另请参阅:
. 因为此解决方案可能需要您将焦点从mod_alias更改为mod_rewrite。

您只需使用此选项即可

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

仔细检查一下,您的控制器名称是什么?“
/files/eeeee/product\u details?pro\u id=11
”-大概应该是
/files/eeeeee/product\u details.php?pro\u id=11
?您在应用程序中看到了什么URL?您的代码片段似乎与您的要求完全相反?@vimalkumar检查快照,它显示
GET
params。您面临的问题是什么?我已将您的代码置于htaccess中,但其加载to@vimalkumar它加载到哪里?“从mod_别名到mod_重写”-
重定向匹配
是mod_别名指令吗
RedirectMatch
也与查询字符串不匹配,它仅与URL路径匹配。