【问题标题】:301 Redirect a directory only if there is no subdirectory / page301 仅当没有子目录/页面时才重定向目录
【发布时间】:2015-10-12 21:13:49
【问题描述】:

我需要使用 .HTACCESS 文件从一个目录的根目录创建一个 301 重定向:

www.domain.com/source/?var=1 ----> www.domain.com/target/?var=1

但如果 url 包含任何页面或子目录,则不存在:

www.domain.com/source/pretty_page/?var=1

【问题讨论】:

    标签: apache .htaccess redirect


    【解决方案1】:

    您可以在 DOCUMENT_ROOT/.htaccess 文件中使用此规则:

    RewriteEngine On
    
    RewriteRule ^source/?$ /target [L,NC,R=301]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-23
      • 2022-12-09
      • 2012-12-18
      • 2021-04-04
      • 1970-01-01
      • 1970-01-01
      • 2014-09-09
      • 2014-11-26
      相关资源
      最近更新 更多