1

I've rewritten my web app using CakePHP, but now I need to have my old formatted urls redirect to my new url format. I can't seem to add my own custom mod rewrite rule. I've added it above the main cakephp rewrite rule, but I'm getting an infinite redirect loop. I just want http://mysite.com/index.php?action=showstream&nickname=user to redirect to http://mysite.com/user before the cakephp rewrite happens.

EDIT: Ok, so now when the condition is met it's redirecting but it's appending the original query string to the end. I'm assuming that's due to the QSA flag in CakePHP rewrite rules, but I was under the impression the "L" in my rule would stop that from executing...

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]

4

2 回答 2

1

When you do a capture inside the RewriteCond line instead of the RewriteRule, you have to reference the capture with %N instead of $N. That is, your RewriteRule line should be:

RewriteRule ^index.php$ /%1 [R=301,L]
于 2009-03-01T08:41:26.187 回答
1

Try to test the request line (THE_REQUEST) to see what URI originally has been requested:

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]

But maybe it would be easier to do this with PHP.

于 2009-03-01T09:07:38.963 回答