1

I have tried numerous variations of redirects, rewrites conditions and rules based on research and although I know I have a lot to learn with redirects, I am really struggling to figure out how to redirect a query string to my root directory :/

I need to redirect http://www.stapletondenver.com/news/press_detail.asp?pressReleaseID=10 to http://www.stapletondenver.com

Again, I've tried a few variations including below:

RewriteCond %{QUERY_STRING}  ^/news/press_detail.asp?pressReleaseID=10$
RewriteRule (.*)  /?  [R=301,L]

Am I on the right track and/or what am I doing wrong? All and any help is greatly appreciated, thanks in advance!

user2105735
  • 55
  • 1
  • 8

1 Answers1

2

Try:

RewriteCond %{QUERY_STRING}  ^pressReleaseID=10$
RewriteRule ^/?news/press_detail\.asp$  /?  [R=301,L]

The %{QUERY_STRING} variable is only the query string, not any part of the URI.

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • Thanks @JonJin, that makes sense for the query string but unfortunately that still does not work. Do I have to have anything else for the root directory/path by chance? – user2105735 Jan 16 '15 at 21:51
  • Is your ht access file in your document root? – Jon Lin Jan 16 '15 at 22:00
  • Yes, and I have a bunch of other redirects in my htaccess that are working. However, this is a Wordpress site - do I need an additional htaccess in the theme root or something? :/ Also, I came across this thread just now that you answered a similar question. Does this apply to my question by chance? - http://stackoverflow.com/questions/13003319/htaccess-rewrite-query-string-as-path – user2105735 Jan 16 '15 at 22:09
  • 1
    You need to make sure those rules are beforr any wordpress rules – Jon Lin Jan 16 '15 at 22:29
  • Wow, that is it. Thank you, thank you! I will now add the other hundreds of query string redirects. Thanks again, your a great resource! – user2105735 Jan 16 '15 at 22:41