I have a site that functions using a “language” URI attribute to set language
oursite.com/home?language=en
We need to be able to also use SEO friendly 2 character URI preppenders
oursite.com/en/home
I’m currently doing a redirect to the index.php file in .htaccess with a few exceptions so my .htaccess has these 2 lines for rewrites
RewriteRule ^([a-z]{2}|[a-z]{2}-[A-Z]{2})/(.*)? ?$2/language=$1
RewriteRule !^(index\.php|robots\.txt|sitemap\.xml|robots\.txt) /index.php?/$1
I need to do a logical rewrite to end up with
/index.php?/home?language=en
What would be the correct Rewrite rule set to make this happen? Is it really even possible?
The
RewriteRule !^(index\.php|robots\.txt|sitemap\.xml|robots\.txt) /index.php?/$1line isn’t going to work because you can’t create a backreference to a negative match.Also, a request like:
/index.php?/home?language=enis kind of ambiguous, the?is reserved and needs to be encoded in the query string, otherwise, it can be appended (so that?becomes a&). Try something like:This takes:
http://oursite.com/en/homeand rewrites it internally to the URI/index.php?/home&language=en. But if you literally want an encoded?in the query string then change the second rule to: