.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:

http://website.com/photo/one-beautiful-photo

      

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

http://website.com/photo/new-photo?slug=old-photo

      

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

http://website.com/photo/new-photo

      

+3


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]

      

+1


source







All Articles