Hey All, a question about mod-rewrite. When user inputs /somepage?ln=xx
my server loads invisibly /xx/somepage
which is much a beautiful url.
BUT, those ugly pages still reappear cached and i just wish them to permanently redirect to the nice urls. so they would disappear and only beautifull urls would remain.
/somepage?ln=xx
should permanently 301 redirect to /xx/somepage
which then would load invisibly the page without showing ugly url. When no language is set, assume english:
/somepage
should redirect to /en/somepage
In both cases,the file extension should be optional (e.g. should work with and without various extensions) .php .htm .pag, in other words all 3-char-extensions should work too, if those urls have them).
/contact?ln=xx or /contact.zzz?ln=xx
should go both to /xx/contact
language is only 2-chars. What i now have:
# make language as a /lang/page like /xx/contact WORKS
RewriteRule ^([a-z][a-z])/(.*) /$2?ln=$1 [L]
# when no page, only language set, go to root /nl or /nl/ WORKS
RewriteRule ^([a-z][a-z])/?$ /$1/home [R=301,L]
# permanently redirect ugly urls to nice ones, so the ugly ones dissappear
RewriteRule ???
So you're redirecting the ugly URL to the nice URL and then rewriting it back again?
I think the trick here is to use RedirectMatch instead of RewriteRule (check you have the module loaded):
However, I really don't know how well that will behave when you're essentially creating a loop. It should work, since the
Redirect
part instructs the browser to request the 'nice' URL, but the Server is then quietlyRewriting
it back to the 'ugly' one for processing.The crux is that if the rewritten URL is then processed again by the redirect, your server may implode into a mini black hole. I'm not sure.
(Edited for clarity.)