views:

16

answers:

2

Like described in the title i would like to have clean URLs with mod_rewrite, sadly i didnt manage to write the fitting regex to get the job done i am experimenting with:

1.try:

RewriteRule ^([a-z]*)$ /index.html?city=$1 [NC,L]

2.try:

RewriteRule ^(.*)$ /index.html?city=$1 [NC,L]

But none is working properly, even less when it comes to "üöä"

+2  A: 

The second one would be better, however, it'll go in a loop as the redirect to /index.html?city=$1 will be processed as well, and as it matches the RewriteRule it will also be redirected. Something like:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.html?city=$1 [NC,L]

will work better as it ensures it only redirects requests that aren't for existing files or directories. I tried the "münster" example with the above and it redirected as /index.html?city=m%c3%bcnster which may or may not be what you require.

Mike Anchor
A: 

Hey thanks for the fast answer! Its actually for this site: http://www.example.de/ I put your code and it works better than with mine, because no loops! Thanks a lot didnt know how to solve that. but its still not working properly. www.example.de/berlin will show the page but not with "city=berlin" because www.example.de/index.html?city=berlin works. whats still wrong?

kritop
That really should be a comment not an answer, but to answer this question, change the RewriteRule line to "RewriteRule ^(.*)$ /index.html?city=$1 [NC,L,R]" and it should work fine.
Mike Anchor
i know i couldnt find the "add comment" comment button anywhere above!? It works but now it gets redirected and it shows the unclean URL again!?
kritop
ah, so you want the nice URL. In that case, you need to change the JavaScript you use to find the selected city. Without the "R" in the square brackets makes the redirect internal to Apache and so the browser doesn't see the "city=xyz" part and so can't process it.
Mike Anchor
Ah, what an enlightment!OK, so I have to write it out with PHP. Thanks a lot, now i can go to sleep!
kritop