htaccess:检查url中的字符串,并重定向到没有该字符串的相同url

时间:2016-09-05 15:50:53

标签: apache .htaccess redirect mod-rewrite

我的网站目前的网址结构是这样的:

http://www.example.com/en-US/foo/bar 
http://www.example.com/es-ES/baz
http://www.example.com/fr-FR/1/2/3

现在我需要删除语言部分并将网址重定向到:

http://www.example.com/foo/bar 
http://www.example.com/baz
http://www.example.com/1/2/3

所以,基本上我需要检查我的网址是否包含一个lang代码(en-US,fr-FR,es-ES ...),如果是,则重定向到相同的网址,不包含该代码。 我怎么能用htaccess做到这一点?

这是我目前的htaccess:

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^(admin)($|/) - [L]

# redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# redirect from .com to .co.uk
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [R=301,L]

RewriteRule ^(.*)/homepage$ /pages/index.php?lang=$1 [L]
RewriteRule ^(.*)/404$ /pages/404.php?lang=$1 [L]
RewriteRule ^(.*)/contents/register$ /pages/registrazione.php?lang=$1 [QSA,L]
RewriteRule ^(.*)/contents/account$ /pages/account.php?lang=$1 [QSA,L]
RewriteRule ^(.*)/info/(.*)$ /pages/$2.php?lang=$1 [L]
RewriteRule ^(.*)/search$ /pages/risultati-ricerca.php?lang=$1 [QSA,L]

RewriteRule ^(.*)/shop/(.*)/(.*) /pages/dettaglio-articolo.php?lang=$1&coll=2&slug=$3 [L]
RewriteRule ^(.*)/store/(.*)/([1-3]+)/(.*)/(.*) /pages/dettaglio-articolo.php?lang=$1&coll=2&num_cat=$3&cat=$4&slug=$5 [L]

RewriteRule ^(.*)/store/shoppingcart$ /pages/carrello.php?lang=$1 [QSA,L]
RewriteRule ^(.*)/store/login /pages/login.php?lang=$1 [QSA,L]
RewriteRule ^(.*)/store/forgot$ /pages/forgot.php?lang=$1 [QSA,L]
RewriteRule ^(.*)/store/register /pages/registrazione.php?lang=$1 [QSA,L]

RewriteRule ^(.*)/buy/checkout /pages/ordine_indirizzo.php?lang=$1 [QSA,L]
RewriteRule ^(.*)/buy/payment /pages/ordine_pagamento.php?lang=$1 [L]
RewriteRule ^(.*)/buy/confirm /pages/ordine_conferma.php?lang=$1 [L]
RewriteRule ^(.*)/buy/order-confirm-ko$ /pages/ordine_conferma-pagamento.php?lang=$1&result=ko [QSA,L]
RewriteRule ^(.*)/buy/order-confirm$ /pages/ordine_conferma-pagamento.php?lang=$1&result=ok [QSA,L]

0 个答案:

没有答案