Belucci
Belucci

Reputation: 21

.htaccess Rewrite url to query string

When I upload images to my website, their links look like this:

https://mywebsite.com/photo/9/ etc.. only the number changes

I want to rewrite it to be query string, like this:

https://mywebsite.com/p?id=9 etc..

This is what I tried to do, but it doesn't work:

RewriteRule ^/photo/([0-9]+) /p?id=$1

Upvotes: 2

Views: 91

Answers (2)

Joe
Joe

Reputation: 4897

Try using this:

RewriteEngine On
RewriteRule ^photo/([^/]*)$ /p?id=$1 [L]

Upvotes: 1

Amit Verma
Amit Verma

Reputation: 41249

Remove the leading slash from RewriteRule's pattern,try :

RewriteRule ^photo/([0-9]+)/?$ /p?id=$1 [L]

Upvotes: 0

Related Questions