1
votes

I would like to redirect in htaccess

https://www.example.com/albumgallery.php?id=8 

to https://www.example.com/example-gallery

i've tried :

RewriteCond %{QUERY_STRING} ^id=8$
RewriteRule ^albumgallery.php$ https://www.example.com/example-gallery? [L,R=301]

-- it works , but on page it says

Not Found The requested URL /example-gallery was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

any ideas what is wrong with that ?

1

1 Answers

0
votes

You are getting a 404 not found error because www.example.com/example-gallery does not exist on your server. You need to rewrite this url to your existing url. for example when you type https://www.example.com/albumgallery.php?id=8 into your browser your rule redirects it to https://www.example.com/example-gallery since this new url doesn't exist so your server returns a 404 error status. You need to add an internal RewriteRule to your htaccess to handle your new url.

Put the following right bellow your existing Rule

 RewriteRule ^example-gallery/?$ /albumgallery.php?id=8&loop=no [L]

I added an additional perameter loop=no to the Rule`s destination it's to prevent infinite loop error so that the rule can not conflict with your existing RewriteRule.