【问题标题】:htaccess redirection 301 in apache 2.4 not workingapache 2.4中的htaccess重定向301不起作用
【发布时间】:2019-04-04 07:32:42
【问题描述】:

如何将目录http://www.example.com/contact/重定向到文件http://www.example.com/contact-us.php

我的 htaccess 文件内容

RewriteEngine On 
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^/contact/$ http://www.example.com/contact-us.php [L,R=301]

【问题讨论】:

    标签: .htaccess redirect apache2.4


    【解决方案1】:

    重写规则 ^/contact/$ http://www.example.com/contact-us.php [L,R=301]

    ^/ 在 htaccess 的 RewriteRule 中永远不会匹配。如果这是在文档根目录中,请删除第一个 /。

    当在 .htaccess 中使用 mod_rewrite 时,将您带到该 htaccess 文件的 URL 路径已被剥离,您只匹配相对/剩余路径。

    【讨论】:

      猜你喜欢
      • 2013-04-06
      • 2017-06-30
      • 2014-07-05
      • 2014-12-21
      • 2011-03-08
      • 1970-01-01
      • 2013-03-14
      相关资源
      最近更新 更多