1

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

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

1 Answer 1

0

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]
4
  • after this all links like domain.com/photos?photoId=something start to redirect to domain.com/photos/something, but go to 404 page =( Commented Mar 15, 2017 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! Commented Mar 15, 2017 at 9:41
  • Here is my htaccess link. I changed regex for only numbers. But there is no result Commented Mar 15, 2017 at 11:21
  • Maybe RewriteCond with Query string can affect for it? Commented Mar 15, 2017 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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