使用.htaccess重写URL(删除$ _GET变量)

时间:2015-07-31 15:52:08

标签: php apache .htaccess codeigniter mod-rewrite

我有这个网址:https://example.com/beehive_deposit?id=6a23361b37MjE-&owner_cus_id=607dde5711MQ--

我想在此转换它:

https://example.com/beehive_deposit/6a23361b37MjE-/607dde5711MQ--

  

我在PHP中使用codeigniter框架。

我在.htaccess中尝试了类似的内容:

RewriteEngine on
RewriteBase /
RewriteRule ^beehive_deposit/([^/.]+)/?$ beehive_deposit?id=$1 [L,QSA,NC]

HTML:

<a href="/beehive_deposit?id=b5347cb1cdMjE-&amp;owner_cus_id=d6cc12707fMQ--"></a>

1 个答案:

答案 0 :(得分:4)

你错了。您输出到客户端HTML的URL应该已经在&#34; clean&#34;格式:

<a href="https://example.com/beehive_deposit/6a23361b37MjE-/607dde5711MQ--"></a>

然后你的重写规则变成(基本上):

RewriteRule ^beehive_deposit/(.*)/(.*)$ beehive_deposit.php?id=$1&cus_id=$2