【问题标题】:Correct syntaxt for multiple 301 redirects in htaccesshtaccess 中多个 301 重定向的正确语法
【发布时间】:2017-03-18 17:20:28
【问题描述】:

我正在尝试将多个页面从旧 URL 重定向到新 URL。

Redirect 301 /eng/loc.php /en/location/
Redirect 301 /eng/rest.php /en/restaurant
Redirect 301 /eng/accom.php /en/accommodation-rates
Redirect 301 /eng/fish.php /en/fishing
Redirect 301 /eng/hiking.php /en/hiking-cycling

这在我添加这一行之前有效:

Redirect 301 /eng /en/home

添加它会导致第一个代码块中的 URL 输出错误。我认为这是由于我的语法错误造成的冲突,但在 stackoverflow 中找不到类似的解决方案,并且无法将我的问题应用于 htaccess 文件的文档。

我已尝试在上一行的“/eng”中添加转义符 \ 和 \s,但这不是问题。

这里的正确语法是什么?

【问题讨论】:

    标签: apache .htaccess redirect


    【解决方案1】:

    实际的解决方案是使用RedirectMatch 作为“目录”。我后来在重定向其他链接时发现,每个 url 引号的原始“解决方案”是错误的。

    RedirectMatch 301 ^/eng$  /en/home  
    Redirect 301 "/eng/loc.php" "/en/location/"
    Redirect 301 "/eng/rest.php" "/en/restaurant"
    Redirect 301 "/eng/accom.php" "/en/accommodation-rates"
    Redirect 301 "/eng/fish.php" "/en/fishing"
    Redirect 301 "/eng/hiking.php" "/en/hiking-cycling"
    

    这是我找到解决方案的地方:http://www.askapache.com/htaccess/301-redirect-with-mod_rewrite-or-redirectmatch/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-29
      • 2020-12-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多