首页 > 解决方案 > Detect a specific pattern inside a url /us-en/ to something else

问题描述

I'm looking for a way to replace a part in a url with another part.

Here is the url:

http://localhost:8888/sa-ar/product-list.html?category=154

I want to replace this part /sa-ar/ with /web/

knowing that /sa-ar/ may change dynamically to any other country and language something like /us-en/ etc.

what is the correct regex to be able to detect the pattern /sa-ar/

This is what I have achieved so far \/(\S{2}-\S{2})\/ Which works except when applied to .htaccess it wouldn't

标签: regex.htaccessdirective

解决方案


RewriteRule ^[a-z]{2}-[a-z]{2}/(.+) /web/$1 [R=301,L]

推荐阅读