I have an URL:

domain.com/photos?photoId=344

and I want to make pretty URL such as:

domain.com/photos/344

I tried to correct htaccess:

RewriteRule ^photos/([A-Za-z0-9-]+) /photos?photoId=$1 [L]

But when clicking domain.com/photos/344 - i go to 404 error.

Maybe the error in Joomla SEF plugin? It's ON

  • Quick question: are your photoIds numbers only or may include letters as well? – nyedidikeke Mar 15 '17 at 9:33
  • @nyedidikeke Only numbers – user3774771 Mar 15 '17 at 9:34
  • Updated my answer to reflect that (numbers only, from 0 to 9). – nyedidikeke Mar 15 '17 at 9:45
  • Hope your challenge is now resolved! – nyedidikeke Mar 15 '17 at 10:19
  • @nyedidikeke Sorry, but there is changes after correct. Maybe you have once more idea? – user3774771 Mar 17 '17 at 3:32

This approach assumes you have mod_rewrite enabled.

You should go about this way:

Options -MultiViews
RewriteEngine On

# First, do redirect "/photos?photoId=something" to "/photos/something"
RewriteCond %{THE_REQUEST} \s/photos\?photoId=([0-9]+)\s [NC]
RewriteRule ^ /photos/%1? [R=301,L]

# Then, internally rewrite "/photos/something" to "/photos?photoId=something"
RewriteRule ^photos/([0-9]+)$ /photos?photoId=$1 [L]
  • after this all links like domain.com/photos?photoId=something start to redirect to domain.com/photos/something, but go to 404 page =( – user3774771 Mar 15 '17 at 9:33
  • @user3774771: Can you elaborate further? Do you have other rules defined in your .htaccess file that possibly conflict with the above? It should actually work! – nyedidikeke Mar 15 '17 at 9:41
  • Here is my htaccess link. I changed regex for only numbers. But there is no result – user3774771 Mar 15 '17 at 11:21
  • Maybe RewriteCond with Query string can affect for it? – user3774771 Mar 15 '17 at 11:23

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.