我有一個鏈接象下面這樣:如何在PHP中使用htaccess代碼進行URL重寫?
在/country/search.php
<a href="<?php echo 'index.php?departments='.$value['department_id'].'&towns='.$value['town_id'].'&type='.$value['type_id'].'&id='.$value['id'] ?>">
當我使用下面.htaccess
代碼,它什麼都不做:
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /country/index.php?departments=$1&towns=$2&type=$3&id=$4 [L]
它在該工具:
http://example.com/0/0/4/122
...但是當我點擊該鏈接時,它會再次顯示舊網址。
這裏有什麼問題?
我生成使用此工具.htaccess
代碼:http://www.generateit.net/mod-rewrite/
你的鏈接已經看起來像你想要做的請求 - 那麼你想要做什麼? – kero
yes.it @ kingkero.I想使它像http://example.com/0/0/4/122,但htaccess代碼不工作 – underscore
htaccess代碼只重寫您的網址,以便請求結束在正確的地方。您使用應用程序生成的鏈接不受htaccess的影響。你必須自己以正確的方式格式化它。 –