Reputation: 35213
My .htaccess file:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ photo.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ photo.php?id=$1
My goal is to convert the url mysite.com/photo.php?id=31
to mysite.com/31
. But when i visit mysite.com/31
, all i get is:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Im running it on a wamp server.
Edit:
My current url looks like this: http://localhost:8080/img/photo.php?id=1
. Do i need to add the /img
-part to htaccess?
Upvotes: 1
Views: 287
Reputation: 143906
If you want to be able to access images via the URL http://mysite.com/31
, note, there is no /img/
directory in the URL, you need to put your rewrite rules in an htaccess file in your document root. The directory that the img
directory is in. Since I'm also going to assume you've got other stuff on your site besides images, you're going to want to check that you are rewriting requests that aren't for images, and you can do that by checking against %{REQUEST_FILENAME}
and the !-f
and !-d
flags.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/?$ /img/photo.php?id=$1 [L]
Also, since your existing rules are just fine if you are trying to access your images via URLs like: http://mysite.com/img/31
, there is something else that is causing your 500 server error. Please make sure that the rewrite module is loaded. In WAMP, right click on the WAMP icon and go to apache, then apache module and make sure rewrite module is checked.
Upvotes: 1
Reputation: 1423
Try this
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_\-]+)$ photo.php?id=$1
</IfModule>
Upvotes: 1