【问题标题】:.htaccess rewrite URL with question mark.htaccess 用问号重写 URL
【发布时间】:2021-08-21 16:29:30
【问题描述】:

我有一个名为“Post Affiliate Pro”的程序给我的 htaccess 代码,看起来像这样

# Start Post Affiliate SEO Code----

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f [OR]

RewriteCond %{REQUEST_FILENAME} -d

RewriteRule .? - [S=4]

RewriteRule ^?coupon-code=([a-zA-Z0-9_-]+)\/?$ https://example.postaffiliatepro.com/scripts/l5zhexygnc?a_aid=$1 [R=301,L]

RewriteRule ^?coupon-code=([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)\/?$ https://example.postaffiliatepro.com/scripts/l5zhexygnc?a_aid=$1&a_bid=$2 [R=301,L]

RewriteRule ^?coupon-code=([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)\/?$ https://example.postaffiliatepro.com/scripts/l5zhexygnc?a_aid=$1&a_bid=$2&chan=$3 [R=301,L]

RewriteRule ^?coupon-code=([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)\/?$ https://example.postaffiliatepro.com/scripts/l5zhexygnc?a_aid=$1&a_bid=$2&chan=$3&data1=$4 [R=301,L]

RewriteRule ^?coupon-code=([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)\/?$ https://example.postaffiliatepro.com/scripts/l5zhexygnc?a_aid=$1&a_bid=$2&chan=$3&data1=$4&data2=$5 [R=301,L]

# End of Post Affiliate SEO Code

这会破坏我的网站,因为我尝试重定向的 URL 开头有一个查询字符串,例如 https://example.com/?coupon-code=PGZ

我知道我需要以某种方式使用 QUERYSTRING 对其进行修改,但我不知道具体该怎么做。谁能帮我修改这个 htaccess 代码,以免破坏我的网站?

【问题讨论】:

    标签: apache .htaccess redirect mod-rewrite query-string


    【解决方案1】:

    根据您显示的尝试/示例,请尝试在您的 .htaccess 文件中遵循规则文件。请确保在测试您的 URL 之前清除您的浏览器缓存。

    ##Making RewriteEngine ON here.
    RewriteEngine On
    ##For existing pages rules here..
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule .? - [S=4]
    
    ##For handling 4 parameters handling rules here.
    RewriteCond %{QUERY_STRING} ^coupon-code=([\w-]+)/([\w-]+)/([\w-]+)/([\w-]+)/?$ [NC]
    RewriteRule ^/?$ https://example.postaffiliatepro.com/scripts/l5zhexygnc?a_aid=%1&a_bid=%2&chan=%3&data1=%4 [R=301,L]
    
    ##For handling 3 parameters handling rules here.    
    RewriteCond %{QUERY_STRING} ^coupon-code=([\w-]+)/([\w-]+)/([\w-]+)/?$ [NC]
    RewriteRule ^/?$ https://example.postaffiliatepro.com/scripts/l5zhexygnc?a_aid=%1&a_bid=%2&chan=%3 [R=301,L]
    
    ##For handling 2 parameters handling rules here.
    RewriteCond %{QUERY_STRING} ^coupon-code=([\w-]+)/([\w-]+)/?$ [NC]
    RewriteRule ^/?$ https://example.postaffiliatepro.com/scripts/l5zhexygnc?a_aid=%1&a_bid=%2 [R=301,L]
    
    ##For handling 1 parameters handling rules here.
    RewriteCond %{QUERY_STRING} ^coupon-code=([\w-]+)/?$ [NC]
    RewriteRule ^/?$ https://example.postaffiliatepro.com/scripts/l5zhexygnc?a_aid=%1 [R=301,L]
        
    ##For handling 5 parameters handling rules here.
    RewriteCond %{QUERY_STRING} ^coupon-code=([\w-]+)/([\w-]+)/([\w-]+)/([\w-]+)/([\w-]+)/?$ [NC]
    RewriteRule ^/?$ https://example.postaffiliatepro.com/scripts/l5zhexygnc?a_aid=%1&a_bid=%2&chan=%3&data1=%4&data2=%5 [R=301,L]
    
    # End of Post Affiliate SEO Code
    

    【讨论】:

      猜你喜欢
      • 2013-09-03
      • 1970-01-01
      • 2021-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-02
      • 2013-12-24
      • 1970-01-01
      相关资源
      最近更新 更多