Click to See Complete Forum and Search --> : apache rewrite
saturngod
08-07-2009, 01:46 AM
I want to redirect
index.php?message=test
to
index.php/message/search/test
Now,I write .htaccess it like that
RewriteEngine on
RewriteCond %{QUERY_STRING} message=^(.*)$
RewriteRule ^(.*)$ /index.php/message/find/$1 [L]
I call index.php?message=test and it's not redirect. How should I write htaccess file.
solowandererY2K
08-07-2009, 03:05 AM
Why do you want to rewrite the URI when you could just use the GET parameter passed in the query string? I get the feeling that your index.php file will have to parse that query string again at some point. Are you using a framework?
I haven't tested anything, but just a quick glance gets my regex senses tingling:
Your RewriteCond directive uses ^ and $; those match the beginning and end of a string. They don't make sense when you're trying to capture something in the middle.
Why are there parentheses around the .* in your RewriteRule? I take it your backreference $1 refers to the (.*) in the RewriteCond (which is a somewhat advanced feature -- nice job).
solowandererY2K
08-07-2009, 03:32 AM
I wish vBulletin had an "edit" button on personal posts...
First of all, backreferences to RewriteCond directives are preceded with %, not $. You would use %1 instead of $1.
Also, remember that, at some point, index.php has to decode its PHP_SELF string to extract the message name. You might want to modify the original script instead.
Here's something that works:
RewriteEngine on
RewriteCond %{QUERY_STRING} message=(.*)
RewriteRule ^(.*)$ index.php/message/search/%1?
Note the question mark at the end -- it clears out the query string. Not sure why mod_rewrite cares about that...