-1

I've been struggling to do 301 redirects, and none of the existing topics helps.

I need to make redirects with .htaccess for the following pages:

Redirect 301 http://www.mypage.com/?q=company/contacts http://www.mypage.com/contacts 
Redirect 301 http://www.mypage.com/?q=product/new/ghz/name-5 http://www.mypage.com/name-5

I know that I should use rewrite rules and specify {QUERY-STRING} and believe me, I've tried. Nothing helps.

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

2

Matching against the actual request:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?q=company/contacts
RewriteRule ^$ http://www.mypage.com/contacts? [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?q=product/new/ghz/name-5
RewriteRule ^$ http://www.mypage.com/name-5? [R=301,L]

Or the query string (this matches rewritten URIs)

RewriteCond %{QUERY_STRING} ^q=company/contacts$
RewriteRule ^$ http://www.mypage.com/contacts? [R=301,L]

RewriteCond %{QUERY_STRING} ^q=product/new/ghz/name-5$
RewriteRule ^$ http://www.mypage.com/name-5? [R=301,L]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • It does redirect, but the URL appears as follow in both cases: http://www.mypage.com/contacts?q=company/contacts and it should appear as mypage.com/contacts and that's it – Tom Tom Jul 25 '12 at 11:19
  • @TomTom oh, forgot to remove the query string, see edit (needed a **?** at the end) – Jon Lin Jul 25 '12 at 11:21