【问题标题】:Apache RewriteRule for a single static URL?单个静态 URL 的 Apache RewriteRule?
【发布时间】:2020-07-16 12:47:15
【问题描述】:

我当前的.htaccess 包含以下内容:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteRule ^(.*)-p-(.*).html$ product_info.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-c-(.*).html$ categories.php?cPath=$2&%{QUERY_STRING}

如何添加单个静态规则,以便将 product1-p-123.html 重定向 (301) 到 product2-p-456.html 而不会中断其他传入请求?

【问题讨论】:

    标签: regex apache .htaccess redirect mod-rewrite


    【解决方案1】:

    这样吧:

    Options +FollowSymLinks
    RewriteEngine on
    
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
    
    RewriteRule ^product1-p-123\.html$ /product2-p-456.html [L,NC,R=301]
    
    RewriteRule ^.+-p-([^.]+)\.html$ product_info.php?products_id=$1 [L,QSA,NC]
    
    RewriteRule ^.+-c-([^.]+)\.html$ categories.php?cPath=$1 [L,QSA,NC]
    

    【讨论】:

      猜你喜欢
      • 2016-06-05
      • 1970-01-01
      • 2012-04-03
      • 2017-04-20
      • 2014-09-16
      • 2020-03-08
      • 1970-01-01
      • 1970-01-01
      • 2013-09-30
      相关资源
      最近更新 更多