.htaccess 301 Redirect (old url for new update) with php get request

I am trying to redirect several old urls to new ones using htaccess, which rewrites the GET request in my PHP file to clean up the urls:

Options +FollowSymLinks
RewriteEngine on
RedirectMatch 301 /photo/old-photo /photo/new-photo    
RewriteRule ^photo/(.*)/?$ tpl-photo.php?slug=$1
RewriteRule ^photo/(.*)?$ tpl-photo.php?slug=$1


This outputs my clean urls like so:



However, when I try to redirect old urls to new urls it messes up the url somehow:



How can I fix this to get the correct clean url:




source to share

1 answer

Don't mix rules mod_rewrite

and mod_rewrite

and only keep rules mod_rewrite


Options +FollowSymLinks
RewriteEngine on

RewriteRule ^photo/old-photo/?$ /photo/new-photo [NC,L,R=301]
RewriteRule ^photo/([^/]+)/?$ tpl-photo.php?slug=$1 [L,QSA,NC]




All Articles