Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule with question mark?

         

Bayarhuu

2:11 pm on Jan 15, 2011 (gmt 0)

10+ Year Member



Hello guys!

I need some help.

I want to rewrite this URL www.example.com/index.php?c=$1&a=$2 to www.example.com/$1?$2

I wrote:

RewriteEngine On
RewriteRule ^/?([^/][^\./]*)[:;,\.]*$ index.php?c=$1&%{QUERY_STRING} [L]


It is just rewrite to www.example.com/$1?a=$2
So how can I remove (a=) ?

Please help me.

jdMorgan

4:49 pm on Jan 16, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Taking your requirement from your text rather than inferring it from your code, I'd say you want something like this:

# Internally rewrite requests for /index.php?c=<value1>&a=<value2>
# or /?c=<value1>&a=<value2> to /<value1>/index.php?<value2>
RewriteCond %{QUERY_STRING} ^c=([^&]+)&a=([^&]+)$
RewriteRule ^(index\.php)?$ /%1/index.php?%2 [L]

If the comment on this rule is incorrect for your exact needs, then this rule is also incorrect.

Jim

Bayarhuu

3:07 am on Jan 17, 2011 (gmt 0)

10+ Year Member



Thanks, but I want to rewrite for /index.php?c=<value1>&a=<value2> to /<value1>?<value2>

g1smd

8:37 am on Jan 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Are you sure you want in internal rewrite?

Or do you need an external redirect?

Be very clear about which of those is a/are URL(s) used out on the web, and which is/may be a filepath used only inside the server.

Both of those act on the URL as requested by the browser.