[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 405
  • Last Modified:

301 redirect not working in .htaccess how do I?

I am trying to do a redirect in htaccess but the rule is being ignored.
redirect 301 /index.php?pid=12 http://www.illumitex.com/

I know it works bc I have this code and it redirect the domain to www:
RewriteCond %{HTTP_HOST} !^www\.illumitex\.com [NC]
RewriteRule ^(.*)$ http://www.illumitex.com/$1 [R=301,L]

What I am trying to do is force some spacific older pages back to the main index page or just / .

I have also  tried:
rewriterule index.php?pid=165 http://www.illumitex.com/ [R=301,L]
But that is not working either.
What am I doing wrong?

1 Solution
A question mark is a special character that should be escaped:
You can't include %{QUERY_STRING} (identified by the question mark) as part of the RedirectRule.
You'll want to do something like:

RedirectCond %{QUERY_STRING} ^pid=12$ [NC]
RedirectRule .* http://www.illumitex.com? [R=301,L]

The question mark in the RedirectRule strips the QUERY_STRING from the URL upon redirect.

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now