0

We have multiple old URLs such as:

blog/index.php?d=26&m=12&y=11   
blog/index.php?m=03&y=12&d=22&entry=entry120322-135153
blog/index.php?m=06&y=12&d=&entry=entry120602-191105    
blog/index.php?d=19&m=02&y=12

The logic is always ?d, ?m, or ?y after the index.php.

I need to redirect these all to:

www.domain.com/blog

I've tried several different methods from here, but seem to be getting the logic mixed.

Addendum

Following the TerryE suggestion, when I type in the link

http://www.coreyogaasia.com/blog/index.php?m=12&y=11&d=26&entry=entry111226-110412

in my browser, it resolves to

http://www.coreyogaasia.com/blog/?m=12&y=11&d=26&entry=entry111226-110412

(the index.php is removed). However, it is not going to

http://www.coreyogaasia.com/blog

I am also putting it above the wordpress one:

# BEGIN WordPress 
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase / 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule>
Community
  • 1
  • 1
  • Why not provide some of those examples? Also, *redirect* or *rewrite*? – animuson Jul 18 '12 at 06:26
  • Sorry animuson...not sure what you mean between redirect or rewrite. Basically, all the old blog pages no longer exist, so I need all the old blog addresses to redirect to the main/new blog feed page. – user1533776 Jul 23 '12 at 12:13
  • A redirect actually causes the user to completely reload the page and change to the path specified, while a rewrite just rewrites the path to something else internally. They're similar words but mean completely different things. – animuson Jul 23 '12 at 18:31
  • In that case, I would think I need a "redirect"? Again, the old pages no longer exist. I need to redirect them from all of the old pages to the new blog page. Is that correct? Does that influence TerrE's code he provided? – user1533776 Jul 24 '12 at 06:02
  • Sorry...edited above to show what I did... – user1533776 Aug 13 '12 at 12:47

1 Answers1

1

You need to use a QUERY_STRING condition to look at the parameters, for example:

RewriteEngine  On
RewriteBase    /

RewriteCond %{QUERY_STRING} ^(d|m|y)=\d
RewriteRule blog/index.php  http://www.domain.com/blog?  [R=302,L]

If you want to keep the parameters, then drop the ? in the redirect string. However, if you do this and the target redirects to the same directory then you'll need extra conditions to prevent a direction loop.

Once you've got this working swap the 302 to 301. For more on this see Tips for debugging .htaccess rewrite rules.

Addendum following bump request

If you have an .htaccess in DOCROOT/blog then you need to insert this below the RewriteBase and above the first WP cond/rule:

RewriteCond %{QUERY_STRING} ^(d|m|y)=\d
RewriteRule index.php       http://www.domain.com/blog/?  [R=302,L]
Community
  • 1
  • 1
TerryE
  • 10,724
  • 5
  • 26
  • 48
  • Terry, thank you for the assisance, however, it does not seem to be working. When I type in the link http://www.coreyogaasia.com/blog/index.php?m=12&y=11&d=26&entry=entry111226-110412 in my browser, it resolves to http://www.coreyogaasia.com/blog/?m=12&y=11&d=26&entry=entry111226-110412 (the index.php is removed). However, it is not going to "http://www.coreyogaasia.com/blog". Any ideas? – user1533776 Jul 19 '12 at 03:37
  • I am also putting it above the wordpress one: # BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] – user1533776 Jul 19 '12 at 03:48
  • I've updated your Q. Putting complex code in comments is not a good idea as the formatting is stripped out. If you want to loose the query parameters, then you **must** keep the last `?`before the flags in the RewriteRule). – TerryE Jul 19 '12 at 11:40
  • Thanks TerryE. I added in the code you gave me, leaving in the ? in. If I leave the L in, I get a 500 Server error. If I take out the L, then it redirects me, but keeps the query parameters? – user1533776 Jul 23 '12 at 07:47
  • @user1533776, no it's fine to bump. Just slipped through the net. Sorry. I'll take a look later today. I am in the middle of something now. :-( – TerryE Aug 07 '12 at 08:33
  • Thanks so much TerryE. I really appreciate your help. I have comments above and below. Sorry I'm being dense. From animuson's post, I may need redirects rather than rewrites? Not sure. Basically have a bunch of links to old posts etc that no longer exist, when user types them in, I need them sent to the new blog index page. :) – user1533776 Aug 08 '12 at 08:13
  • Do you have a `DOCROOT/blog/.htaccess`? I've looked at your site and I suspect that this is was is screwing things up. Move the rule to this file as I suggest above. This will stop the 500 loop. PS. I like your site. My wife's been doing yoga for 40 years :) I am lapsed :( – TerryE Aug 10 '12 at 23:51
  • Hey Terry...my wordpress install sits in the root directory...and because it's wordpress, there is no folder called "blog", as it's just a permalink for the blog page (www.coreyogaasia.com/blog). And thanks for the comments on the site! I'm lapsed as well. LOL – user1533776 Aug 13 '12 at 01:24
  • The redirect that you are getting is consistent with leaving out the `?`. That's why you need it. The issue is "what is causing the 500 redirect loop?" when you leave it in. Are you using `http://www.coreyogaasia.com/blog/?` in you replacement string (note the `/`). – TerryE Aug 13 '12 at 08:42
  • How about ticking my answer then? :-) – TerryE Aug 13 '12 at 15:06
  • Sorry bud. Don't use this site often. Hope that was what needed to be done! Cheers! – user1533776 Aug 14 '12 at 03:24