Forum

Thread tagged as: Problem

Blog rewrites interfering with 301

Hello,

I've updated a blog slug format from %Y-%m-%d-{postTitle} to remove the date to be {postTitle}

All working well but after putting 301s in place to redirect the old urls with the date to the new urls

Redirect 301 /blog/2016-03-16-post-title https://site.com/blog/post-title

The redirects result in

https://site.com/blog/post-title?s=2016-03-16-post-title

I'm assuming this line from the htaccess is interfering with it:

RewriteRule ^blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1 [L]

How can I amend the above without breaking it?

Sarah Evans

Sarah Evans 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Which order do you have the rules in?


RewriteRule ^blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1 [L]

Followed by the 301s.

I have switched them to test but not change.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, here's something I didn't know. mod_rewrite rules get executed before mod_alias (Redirect) rules, regardless of the order in which they appear.

So if your old URL matches the rewrite rule, then it'll get rewritten before the Redirect tries to match it.

I think in this case it might be simpler to use mod_rewrite for both.

RewriteRule ^blog/2016-03-16-post-title$ /blog/post-title [R=301]
RewriteRule ^blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1 [L]
Abby Larsen

Abby Larsen 0 points
Registered Developer

Thanks for this! I was having this issue, too, and this fixed my problem.