I'm trying to get the hang of Rewrite rules. I've used some generators and guides to try and understand how it works, and the code I get back is the following:
Options +FollowSymLinks
RewriteEngine on
RewriteRule view_image/img/(.*)/ view_image.php?img=$1
RewriteRule view_image/img/(.*) view_image.php?img=$1
I'm trying to re-direct: http://www.danielfew.uk/projects/file_upload/view_image.php?img=food-qc-1920-1080-2.jpg
To: http://www.danielfew.uk/projects/file_upload/view_image/img/food-qc-1920-1080-2.jpg/
Or even better, redirect: http://www.danielfew.uk/projects/file_upload/view_image.php?img= {image-name}
To: http://www.danielfew.uk/img/ {image-name}
Or thats what the generator say's... but each time I goto that page I get an Internal Server Error.
Can someone give me a hand and help me understand how Rewriting URL's work?
I have removed the content of .htaccess for now so you can view the page without getting Internal Server Error.
So I think this is your solution,
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^img/([0-9]+)/?$ view_image.php?img=$1 [NC,L] # Handle product requests
You like must be like that: http://www.danielfew.uk/projects/file_upload/view_image/img/ {number}/
NOTE: you can not use name here because this codes not support name, only id={number} ok
Here is demo of my testing site, this is my .htaccess codes
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^DanielFew/([0-9]+)/?$ index.php?id=$1 [NC,L] # Handle product requests
and my link is this: http://test.softbazz.com/danielfew/danielfew/3/ By changing the id number you can see the changes. danielfew/{id=number}/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.