Reputation: 752
I've set up htaccess RewriteRules
to rewrite e.g. "domain.ext/en/page"
to "domain.ext?lang=en&p=page"
which works as expected.
However, I want to make the language part optional, so "domain.ext/page"
will also rewrite to "domain.ext?lang=en&p=page"
.
Here's the htaccess code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER} !^domain.ext/.*$ [NC]
Options +FollowSymlinks
RewriteRule ^$ index.php?lang=en
RewriteRule ^(en|nl)/?$ index.php?lang=$1
RewriteRule ^(en|nl)/([^/]+)/?$ index.php?lang=$1&p=$2
So I'd like to add something like:
RewriteRule ^([^/][[NOT (en or nl)]]+)/?$ index.php?lang=en&p=$2
Upvotes: 1
Views: 174
Reputation: 12438
You can try the following regex:
^(?!en|nl)([^/]+)/?$
to rewrite "domain.ext/page"
will also rewrite to index.php?lang=en&p=$2
.
You can also add:
^(?!en|nl)[a-z]{2}/([^/]+)/?$
to rewrite jp/page/
, fr/page/
to index.php?lang=en&p=$2
I hope that it helps you. Good luck :-)
Upvotes: 1