我想寫這個重寫代碼,它只是不工作(阿帕奇2.2):Modrewrite和PHP發出
RewriteEngine on
RewriteBase/
RewriteRule ^account/activate\?token=(.*) index.php?route=account/activate&token=$1
我嘗試了許多不同的變化。經過大約一小時的努力和搜索谷歌後,我很難過。這是你進來的地方!
我想寫這個重寫代碼,它只是不工作(阿帕奇2.2):Modrewrite和PHP發出
RewriteEngine on
RewriteBase/
RewriteRule ^account/activate\?token=(.*) index.php?route=account/activate&token=$1
我嘗試了許多不同的變化。經過大約一小時的努力和搜索谷歌後,我很難過。這是你進來的地方!
試試這個
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^account/activate$ index.php?route=account/activate&%1
這基本上整個查詢字符串映射到%1 RewriteRule,然後你可以使用良好的舊常規$ _GET ['token']從你的php-script訪問你的令牌
我用這個:
RewriteEngine On
RewriteRule ^account/activate/?$ index.php?route=account/activate&%{QUERY_STRING}
RewriteRule ^account/activate/?/$ index.php?route=account/activate&%{QUERY_STRING}
並將其與該工作原理:
<?php
echo "route is: " . $_GET['route'];
echo "</br>";
echo "token is " . $_GET['token'];
我的目錄,我的代碼駐留在被稱爲測試。 這是我的網址:
http://localhost:80/test/account/activate/?token=test
http://localhost:80/test/account/activate/?token=asd
你可以用你的mod_rewrite的URL的參數部分不匹配。
以測試你的URL參數的唯一方法是使用RewriteCond指令和測試環境變量QUERY_STRING
RewriteRule
directive的模式只被再次測試URI路徑。查詢字符串只能與RewriteCond
directive測試:
RewriteCond %{QUERY_STRING} ^token=(.*)
RewriteRule ^account/activate$ index.php?route=account/activate&token=%1
但有一個簡單的解決方案:只需設置QSA
flag獲得自動添加到新的查詢字符串查詢字符串:
RewriteRule ^account/activate$ index.php?route=account/activate [QSA]
注意:如果在替換中定義了查詢,則只需設置QSA
標誌。如果不是,原始查詢已經自動添加。
也許對你想要做的事做一點解釋吧?也許有一些傳入的URI和傳出的例子,以及你希望保留哪些參數? – AlexanderJohannesen 2009-07-27 10:07:10
什麼不起作用?什麼是問題,你想達到什麼目的? – random 2009-07-27 10:07:42
mod_rewrite是否適用於其他規則? – 2009-07-27 10:08:19