David David - 3 months ago 9
PHP Question

Internal Server Error: Having trouble with mod_rewrite in .htaccess

My URL is like this:

http://example.com/Folder/index.php?city=Berlin&id=1


I want to turn it into:

http://example.com/Berlin/1


Using Generate It! I get this code:

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /Folder/index.php?city=$1&id=$2 [L]


But when adding this in my .htaccess file and trying to open
http://example.com/Berlin/1
I'm getting the following error:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, [no address given] 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.

Apache/2.2.14 (Ubuntu) Server at example.com Port 80


What am I doing wrong? I'm trying since hours to get it work, but without success.

Answer

I found the solution:

I'm using this in my .htaccess:

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/id/([^/]*)$ /Folder/index.php?city=$1&title=$2&id=$3 [L]

to change this link:

http://example.com/Folder/index.php?id=566&city=Berlin&title=this_is_the_websites_title

to:

http://example.com/Berlin/this_is_the_websites_title/id/566