首页 > 解决方案 > htaccess 删除国家变量

问题描述

抱歉,我找不到任何解决我的问题的方法。希望各位大神帮忙。

我有网址:

http://example.com/country-prefix/.well-known/other-part

我想把它变成:

http://example.com/.well-known/other-part

所以删除国家前缀,例如:

http://example.com/pl/.well-known/other-part =>  http://example.com/.well-known/other-part

http://example.com/us/.well-known/other-part =>  http://example.com/.well-known/other-part

仅当 /.well-known/ 在 url

我知道可以这样做:

RewriteCond %{REQUEST_URI} /.well-known/
RewriteRule ^/?(pl|eu)/(.*)$ $2

但是是否可以在 RewriteRule 中不包含所有语言前缀(因此它适用于所有语言),例如上面的示例适用于:

http://example.com/pl/.well-known/other-part

但不是为了

http://example.com/us/.well-known/other-part

标签: regex.htaccess

解决方案


感谢:Sumurai8

如果有人需要它:

RewriteCond %{REQUEST_URI} /.well-known/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]+/(.*)$ $1

推荐阅读