开发者

HTaccess remove query string at start of URL

开发者 https://www.devze.com 2023-02-22 03:35 出处:网络
I am using a translation system that is currently not working for non-friendly URLs such as /index.php&option=com_virtuemart&page=shop.browse&category_id=&product_type_id=1&produ

I am using a translation system that is currently not working for non-friendly URLs such as

/index.php&option=com_virtuemart&page=shop.browse&category_id=&product_type_id=1&product_type_1_Height_comp=find_in_set_any&product_type_1_Height[0]=Short+%28up+to+80cm%29&product_type_1_Strain_comp=find_in_set_any&product_type_1_Strain[0]=Asia-Central&product_type_1_Yield_comp=find_in_set_any&product_type_1_Yield[0]=High

So I've added:

RedirectMatch 301 /es/(.*)index.php(.*)$ http://www.seed-city.com/$1

... into my .htaccess file to redirect to the English version. However, it adds ?lang=es&url= to the front of the URL after being redirected to the English version and I'd like to be able to remove it. It can also be ?lang=fr&url= ?lang=de&url= ?lang=zh-CN&url= etc.

I've tried as much as I can think of but I ha开发者_Python百科ven't been able to remove it successfully. Thanks for your time and any help would be greatly appreciated. Thanks, Natastna2.

EDIT:

@vbence Thanks for your reply. I'd like to take this url:

http://www.seed-city.com/?lang=es&url=index.php&option=com_virtuemart&page=shop.browse&category_id=&product_type_id=1&product_type_1_seed_type_comp=find_in_set_any&product_type_1_seed_type[0]=Regular&product_type_1_indoor_flowering_time_comp=find_in_set_any&product_type_1_indoor_flowering_time[0]=Medium+%2856+to+90+days%29&product_type_1_Outdoor_harvest_time_comp=find_in_set_any&product_type_1_Outdoor_harvest_time[0]=Middle+of+September

and change it to:

http://www.seed-city.com/index.php&option=com_virtuemart&page=shop.browse&category_id=&product_type_id=1&product_type_1_seed_type_comp=find_in_set_any&product_type_1_seed_type[0]=Regular&product_type_1_indoor_flowering_time_comp=find_in_set_any&product_type_1_indoor_flowering_time[0]=Medium+%2856+to+90+days%29&product_type_1_Outdoor_harvest_time_comp=find_in_set_any&product_type_1_Outdoor_harvest_time[0]=Middle+of+September

removing the ?lang=es&url= from the beginning. This is because now, if someone clicks the Spanish translation button once, it redirects to the English version fine as it matches my previous rule of:

RedirectMatch 301 /es/(.*)index.php(.*)$ http://www.seed-city.com/$1

However, if they click it once, the URL now starts with ?lang=es&url= and therefore does not match with my previous rule. On their second click on a translation flag, they are taken to the error page rather than the English version which I would prefer. This is why I am trying to remove the query from the front of the URL. The resulting URL should be devoid of language identifiers as it is in the English default language. Thanks for your reply.


If you want to hide lang=foo and simulate a directory like /foo/index.php, you can use this rule instead:

RewriteRule ^([a-z-]+)/index.php index.php?lang=$1 [QSA,L]

Note that I assumed that you use this rule in a .htaccess file. In apache config the URL will start with a /, so you have to add it right after the ^ character.

0

精彩评论

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