Mod_rewrite how to remove URI segment
I hav开发者_如何学JAVAe multiple languages on my web page. Here are link examples:
http://myweb.com/en/page_load/about_us
http://myweb.com/en/page_load/testing
http://myweb.com/de/page_load/about_us
http://myweb.com/de/page_load/testing
I want to make it shorter like this:
http://myweb.com/en/about_us
http://myweb.com/en/testing
http://myweb.com/de/about_us
http://myweb.com/de/testing
Currently I have this in my .htaccess file:
RewriteEngine On
RewriteCond $1 !^(index\.php|images|public|css|blogg|img|captcha|robots\.txt|sitemap.xml|resources)
RewriteRule ^(.*)$ /index.php/$1 [L]
Any suggestions?
You could do this with CodeIgniter's built-in routing. Try something like this in your routes.php
config file.
$route['en/page_load/:any'] = "en/$1";
$route['de/page_load/:any'] = "de/$1";
That should give you what you are looking for.
If you just want to remove the page_load
part, you can just do:
RewriteRule ^(.*)/page_load/(.*)$ $1/$2 [L]
If you want to merge both rules, I recommend you first to use REQUEST_URI
as the RewriteCond
variable (instead of $1
, which depends on the RewriteRule
), and also, if possible, to specify conditions on positive cases instead of negative cases (prefer not using !
for conditions). I think this way would be more maintainable.
精彩评论