Reputation: 1046
Currently my urls links are displaying this way
/news?lang=en
how can i make RewriteRule to display URLS like this
/news/en
This is what i've tried so far
RewriteRule ^?lang=(.*) /$1 [QSA]
I'm no really understanding .htaccess till the end how it exactly works
Upvotes: 0
Views: 278
Reputation: 42885
I'd say that his is what you are looking for:
RewriteEngine on
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^/?news/(en|de|fr|es)/?$ /news?lang=$1 [END]
In case that rule results in an "internal server error" (http status 500), then chances are that you operate a very old version of the apache http server. In that case either update your server or try using the older [L]
flag instead of the [END]
flag. It might work the same, but that depends on the rest of the setup. You will find a clear hint on the [END]
flag not being supported in that case in your http servers error log file.
That rule will work likewise in the http servers host configuration or in a dynamic configuration file (".htaccess" style file). If you really have to use such a dynamic file then take care that it's interpretation is enabled in your host configuration and that above rule is placed in such a file inside the DOCUMENT_ROOT
folder of the http host.
And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).
Upvotes: 1