I am trying to do a Redirect with SOME Querystring Parameters Maintained. I already know how to do a redirect with ALL parameters maintained, or with NO parameters maintained, but in this particular case, i need only ONE of them dropped.

For example, my old links for my old system were something like:
http://linuxintro.com/?a=Article_Page_Display&id=900072752405

But now they are like this:
http://linuxintro.com/?a=WCMS_Page&id=900072752405

So i need to drop the "a" parameter, but keep the "id" parameter, so that i know which article to display.
Thanx

Dani AI

Generated

Nice catch, — your RewriteCond/RewriteRule approach is the right idea. A few refinements make it more robust for real sites: handle the case where id appears before a (or other params exist), stop processing after the redirect, avoid accidental 301 caching while testing, and remember to use literal & in .htaccess (not &).

A more robust, easy-to-read approach (works on Apache 2.2+):

RewriteEngine On

# only when a=Article_Page_Display is present
RewriteCond %{QUERY_STRING} (?:^|&)a=Article_Page_Display(?:&|$) [NC]
# capture id regardless of position in query string
RewriteCond %{QUERY_STRING} (?:^|&)id=([^&]+)(?:&|$) [NC]
# redirect to the new page and pass only the captured id
RewriteRule ^ /?a=WCMS_Page&id=%1 [R=302,L]

Notes and troubleshooting

  • Use R=302 while testing to avoid client-side caching; switch to R=301 when you are sure. Clear browser cache or test with curl -I to see fresh headers.
  • The %1 backreference comes from the last RewriteCond capture.
  • If you are on Apache 2.4+ you can add the QSD flag to explicitly discard any remaining query string: [R=301,L,QSD].
  • Put these rules near the top of your vhost or .htaccess, and ensure mod_rewrite is enabled.
  • If id can contain special characters, consider the NE flag and confirm proper URL-encoding.
  • If you see unexpected redirects, enable rewrite tracing via your server LogLevel (e.g., rewrite:trace3) to diagnose rule ordering.

This keeps the id param reliably, drops the old a value, and avoids leaving other query parameters hanging around.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.