user1533776
user1533776

Reputation: 3

Redirect multiple dynamic URL to single static URL

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>

Upvotes: 0

Views: 559

Answers (1)

TerryE
TerryE

Reputation: 10898

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]

Upvotes: 1

Related Questions