【问题标题】:I have a problem with regex coincidences with a slash我对带有斜线的正则表达式巧合有疑问
【发布时间】:2021-12-13 12:42:23
【问题描述】:

这是我多年来浏览该网站后的第一次发帖。这次我还没有找到如何在 htaccess 中执行此重定向。

我有以下网址:

domain.com/es/category/product1
domain.com/es/product1

我想重定向到:

domain.es/category/product1

我试过这个:

Redirectmatch 301 ^/es/(.*)product1 https://domain.es/category/product1

Redirectmatch 301 ^/en/(.*)/product1 https://domain.es/category/product1

问题是如何设置它以捕获 /en/ 和 product1 之间的所有内容。字母或斜线。

【问题讨论】:

    标签: regex .htaccess redirect


    【解决方案1】:

    根据您显示的尝试,请尝试遵循 htaccess 规则文件。确保将此规则放在 htaccess 文件的顶部(考虑到您可能有其他规则正在这里重写 URL)。确保将您的 htaccess 文件与 es 文件夹保持在同一路径中。

    请确保在测试您的 URL 之前清除您的浏览器缓存。

    ##Enabling rewrite engine here.....
    RewriteEngine ON
    RewriteCond %{HTTP_HOST} ^(www\.)?(domain)\.com$ [NC]
    ##Doing redirect of uris which starts from es may/may not have category after it and redirecting to as per OP's requirement.
    RewriteRule ^(es)/(?:category/)?product1/?$ http://%1.$1/category/product1 [NC,L,R=301]
    

    【讨论】:

      猜你喜欢
      • 2021-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-10
      • 2019-10-04
      • 1970-01-01
      相关资源
      最近更新 更多