I am writing a multi language website. Therefore I would like some help with a URL rewrite problem.
Case:
- When someone visits http://www.example.com without adding a country code (nl, en, de) the htaccess redirects the visitor to http://www.example.com/nl/ i.g.
RewriteRule !(nl|en|de)(.*).* /nl/ [R=301,L] - The website is renewed and has got many url’s directing to the website (google, forums). i.g. http://www.example.com/oldpage-nomore.html. What I would like is the following; the htaccess should detect that the request uri doesn’t contain nl,en or de and should redirect to pagenotfound.php.
RewriteRule ^(.*)\.html /public/oldurl?section=nl¬found=$1$2&basehref=true&%1 [PT,L]the problem with this Rewrite rule is: all files ending in .html are being redirected.
What I am looking for is the following:
- When someone visits http://www.example.com and no request uri is entered this should redirect to http://www.example.com/nl/
- When there is a requested uri and this doens’t contain a countrycode (nl|en|de) than redirect to pagenotfound.php
I tried the following but it doens’t work:
RewriteCond %{REQUEST_URI} !^(nl|en|de)$
RewriteRule ^([a-z]{2})/(.*)\.html$ /pagenotfound.php?page=$2 [L,R=404]
I hope someone can help.
Thank you in advance.
Try to place this .htaccess file at the server root folder:
(you probably made several mistakes, I tried to fix them)
I’m not sure with the first RewriteCond %{REQUEST_URI} regular expression – maybe remove the question mark or slash, I don’t now… can’t test now.