I'm trying to rewrite a URL so that it's user/search engine friendly, then 301 redirect the original URL to the new one.
At the moment the posts generate like this: example.com/blog/post.php?s=nice-post
But I'd like them to look like this: example.com/blog/nice-post
Here's what I've got so far:
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteCond %{QUERY_STRING} ^s=(.+)$
RewriteRule post.php /%1? [R=301,L]
RewriteCond %{REQUEST_URI} !post.php
RewriteRule ^([a-zA-Z0-9_-]+)$ post.php?s=$1
Unfortunately, this clashes with the 404 redirect, sending all pages not found to the blank post.php file, and I can't work out why. Is there a better way of approaching the URL rewrite/redirect?
Thanks for having a look :)