views:

44

answers:

1

I want to rewrite these so that the text in the adress bar should be

mysite.com/citiname.html

A: 

First, make sure you have mod_rewrite enabled in Apache. Also make sure that

 AllowOverride All

is enabled in the conf file. Then create a .htaccess file with the following contents:

RewriteEngine On
RewriteRule ^city/([A-Za-z]+)\.html$ $1.html [L]

The first part of the RewriteRule is the pattern. If the URL matches that pattern, the rule is executed and redirected to the second part. The $1 represents the group matched by ([A-Za-z]+).

So /city/Amsterdam.html is rewritten to /Amsterdam.html

(Btw, I don't have an option to test it atm, it's what I remembered from the rules I wrote in the past)

Mythica
You need to redirect as well to see the new URL, therefore the modifier should be [L,R=301].
Residuum
i get Internal Server Error when i try your code - supermac
Also you need to escape the .:RewriteRule ^/city/([A-Za-z]+)\.html$ /$1.html [L,R=301]
Residuum
Redirecting isn't necessary, since the url is rewritten before being served. Escaping however, is needed.Supermac: check the apache log files to see what's going wrong.
Mythica