.htaccess 301 htaccess使用3个参数重定向到静态URL

.htaccess 301 htaccess使用3个参数重定向到静态URL,.htaccess,redirect,http-status-code-301,.htaccess,Redirect,Http Status Code 301,我试图用3个参数将几个URL重定向到不同的静态URL,但没有任何效果 一, 到 到 到 我尝试了以下代码,但不打算: 如果您从id_lang=variable获取页面的id,请尝试以下规则。请确保在测试URL之前清除浏览器缓存 RewriteEngine ON ##Rules to redirect to link: https://newdomain.com/page1/ here. RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [

我试图用3个参数将几个URL重定向到不同的静态URL,但没有任何效果

一,

  • 我尝试了以下代码,但不打算:


    如果您从id_lang=variable获取页面的id,请尝试以下规则。请确保在测试URL之前清除浏览器缓存

    RewriteEngine ON
    ##Rules to redirect to link: https://newdomain.com/page1/ here.
    RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
    RewriteCond %{THE_REQUEST} \s/index\.php\?id_category=28&controller=category&id_lang=(\d+)\s [NC]
    RewriteRule ^ https://newdomain.com/page%1/? [NE,R=301,L]
    
    ##Rules to redirect https://newdomain.com/ here.
    RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
    RewriteCond %{THE_REQUEST} \s/index\.php\s [NC]
    RewriteRule ^ https://newdomain.com [NE,R=301,L]
    

    您需要先有特定的较长匹配项,然后有规则删除
    index.php
    或域重定向:

    重新编写引擎打开
    #使用index.php作为可选匹配项的特定重定向
    RewriteCond%{QUERY\u STRING}^id\u category=28&controller=category&id\u lang=2$[NC]
    重写规则^(索引\.php)?$https://newdomain.com/page1/? [R=301,L,NC]
    RewriteCond%{QUERY\u STRING}^id\u category=30&controller=category&id\u lang=2$[NC]
    重写规则^(索引\.php)?$https://newdomain.com/page2/? [R=301,L,NC]
    #删除index.php并重定向到newdmain
    RewriteCond%{HTTP_HOST}^(?:www\.)?olddomain\.com$[NC]
    重写规则^(?:index\.php/?)?(*)$https://newdomain.com/$1[L,R=301,北卡罗来纳州,北卡罗来纳州]
    

    在测试此更改之前,请确保清除浏览器缓存。

    欢迎使用SO,感谢分享您的代码。如何传递类别值以将URL重写为index.php文件?请详细说明。下面的代码正在运行,并将类别重定向到新页面。但是不能将首页重定向到和重写cond%{QUERY\u STRING}^id\u category=28&controller=category&id\u lang=2$RewriteRule^index.php$?[R=301,L]RewriteCond%{QUERY_STRING}^id_category=30&controller=category&id_lang=2$RewriteRule^index.php$?[R=301,L]@Chris,你能告诉我我的解决方案是否对你有效吗?谢谢。实际上,此规则不能基于
    id\u lang=
    参数,因为根据OP,这两种情况下都是
    2
    https://newdomain.com/page1/
    
    http://olddomain.com/index.php?id_category=30&controller=category&id_lang=2
    
    https://newdomain.com/page2/
    
    http://olddomain.com/index.php
    
    https://newdomain.com
    
    RewriteCond %{HTTP_HOST} ^olddomain.com [NC,OR]
    RewriteCond %{HTTP_HOST} ^www.olddomain.com [NC]
    RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301,NC] 
    
    RewriteCond %{QUERY_STRING} ^id_category=28&controller=category&id_lang=2$
    RewriteRule ^index.php$ https://newdomain.com/page1/? [R=301,L]
    
    RewriteCond %{QUERY_STRING} ^id_category=30&controller=category&id_lang=2$
    RewriteRule ^index.php$ https://newdomain.com/page2/? [R=301,L]
    
    RewriteEngine ON
    ##Rules to redirect to link: https://newdomain.com/page1/ here.
    RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
    RewriteCond %{THE_REQUEST} \s/index\.php\?id_category=28&controller=category&id_lang=(\d+)\s [NC]
    RewriteRule ^ https://newdomain.com/page%1/? [NE,R=301,L]
    
    ##Rules to redirect https://newdomain.com/ here.
    RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
    RewriteCond %{THE_REQUEST} \s/index\.php\s [NC]
    RewriteRule ^ https://newdomain.com [NE,R=301,L]