Forum Moderators: phranque

Message Too Old, No Replies

Rewriting part of the address / query string

mod_rewrite + .htaccess

         

grey

7:30 pm on Mar 10, 2011 (gmt 0)

10+ Year Member


What I`ve been trying to achieve:

Translate following address
http://domain/path/to/action/?query=string&some=other
to
http://domain/index.php?action=path/to/action&query=string&some=other
with mod_rewrite in .htaccess file. The closest to it what I can get is:

RewriteEngine On
RewriteBase/
RewriteRule^([\w\/]+)$index.php?action=$1 [L]

But that of course will give me http://domain/index.php?action=path/to/action. Anything I`ve tried to add after ([\w\/]+) didn`t fetch me the query string after '?' sign. Obviously I fail at regular expressions :/

Any ideas how it might be done?

jdMorgan

7:46 pm on Mar 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteRule cannot "see" query strings. It examines only the requested URL-path, and not the queries appended to those paths. Use a preceding RewriteCond testing %{QUERY_STRING}

Please specify the originally-requested query parameters in detail. Specifically, are all parameters *always* present and *always* in the same order? If not, please describe all possible valid variants. Also, in your initial "requirements" statement, which is the client-requested URL, and which is the actual server filepath? Or, if you are intending to redirect the client from an old URL to a new URL, then which is old and which is new?

Jim