2009-03-01 35 views
1

我已經使用CakePHP重寫了我的web應用程序,但現在我需要將我的舊格式的url重定向到我的新url格式。我似乎無法添加我自己的自定義國防部隊重寫規則。我已經在主要的cakephp重寫規則之上添加了它,但是我得到了一個無限重定向循環。我只想http://mysite.com/index.php?action=showstream&nickname=user在cakephp重寫之前重定向到http://mysite.com/user如何爲CakePHP路由編寫自定義mod_rewrite .htaccess文件?

編輯:好吧,所以現在當條件滿足時它重定向,但它將原始查詢字符串追加到結尾。我假設在CakePHP中的QSA標誌重寫規則這是由於,但在我印象中我的規則中的「L」將停止從執行下...

RewriteEngine On 

RewriteCond %{QUERY_STRING} ^action\=showstream&nickname\=(.*)$ 
RewriteRule ^.*$ http://mysite.com/%1 [R=301,L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] 

+0

我已更新了我原來的帖子。任何幫助將不勝感激! – makeee 2009-03-01 19:38:08

回答

1

當你做捕獲在RewriteCond行內而不是RewriteRule,您必須使用%N而不是$ N引用捕獲。也就是說,你的重寫規則行應該是:

RewriteRule ^index.php$ /%1 [R=301,L] 
1

嘗試測試請求行(THE_REQUEST)看到URI原本已被要求什麼:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php 
RewriteCond %{QUERY_STRING} ^action=showstream&nickname=([^&]*)$ 
RewriteRule ^index\.php$ /%1? [R=301,L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule .* index.php?url=$0 [QSA,L] 

但也許它會更容易做到這一點與PHP。

相關問題