开发者

Website Language - htaccess RewriteRule

开发者 https://www.devze.com 2023-02-07 02:17 出处:网络
I\'m trying to use 开发者_如何学Gorules and conditions with .htaccess but don\'t know how to do what I need.

I'm trying to use 开发者_如何学Gorules and conditions with .htaccess but don't know how to do what I need.

Here's the scene:

I have a website with many languages. (en|es|pt)

I want to use the urls like this:

 www.site.com/home/ 
 (original url): www.site.com/index.php?p=home
 (opens home.php - session language)

And like this:

www.site.com/en/home/
(original url): www.site.com/index.php?l=en&p=home
(opens home.php - en language)

What are the eules/conditions that I need to create to detect the language in url?

TIA


SOLUTION:

RewriteRule ^(en|es|pt)?\/?([a-z0-9A-Z,_-]+)\/?$ index.php?l=$1&p=$2 [QSA,L]

Thanks

Note: "current solution does also allow something like /enfoobar to be rewritten to /index.php?l=en&p=foobar as the / is independent of the language indicator" - Gumbo


You might probably use something like this

RewriteEngine on
RewriteBase /

RewriteRule ^(en|es|pt)/(.*) /index.php?l=$1&p=$2 [QSA,L]


For any 2digits characters languages

Options +FollowSymlinks RewriteEngine on RewriteRule ^[a-zA-Z][a-zA-Z]/index.html$ index.html?language=$1 RewriteRule ^index.html$ /index.php [L]

0

精彩评论

暂无评论...
验证码 换一张
取 消