Htaccess - redirect changes address bar, why?

software development


I have a site that serves up journal entries with a script “index.php”. The URIs look like:

I wanted to change it so that this can be used, i.e. so the entries don’t look like query string parameters but individual pages:

I tried the following .htaccess script:

RewriteEngine on
RewriteRule ^diary/([0-9].*) http://%{HTTP_HOST}/diary/?e=$1 [L]

This makes the new format work, so that 2009-01-25 redirects to ?e=2009-01-25, but the address bar changes. I don’t want the user to see the ?e= at all. Since I have [L] and not [R] in my htaccess line, that should be the case. But it doesn’t work; the address bar changes.

Please help!


RewriteRule Documentation:

‘redirect|R [=code]’ (force redirect)
Prefix Substitution with http://thishost[]/ (which makes the new URL a URI) to force a external redirection. If no code is given, a HTTP response of 302 (MOVED TEMPORARILY) will be returned. If you want to use other response codes in the range 300-400, simply specify the appropriate number or use one of the following symbolic names: temp (default), permanent, seeother. Use this for rules to canonicalize the URL and return it to the client - to translate /~'' into/u/’’, or to always append a slash to /u/user, etc.
Note: When you use this flag, make sure that the substitution field is a valid URL! Otherwise, you will be redirecting to an invalid location. Remember that this flag on its own will only prepend http://thishost[]/ to the URL, and rewriting will continue. Usually, you will want to stop rewriting at this point, and redirect immediately. To stop rewriting, you should add the ‘L’ flag.

Wat this means is that using the R flag will means you want to redirect but to lazy to prepend the http://hostname yourself and you want Apache to do it for you.

Probably didn’t see the note about per-directory context:
There is one exception: If a substitution string starts with ``http://’’, then the directory prefix will not be added, and an external redirect or proxy throughput (if flag P is used) is forced!

So to sum it up… don’t specify the scheme and hostname in the substitution.

:cool: -//-


Ah, I see. That did the trick. Thank you!