【问题标题】:URL rewriting and 301 redirect in htaccess not workinghtaccess 中的 URL 重写和 301 重定向不起作用
【发布时间】:2013-04-26 13:45:18
【问题描述】:

我想使现有网站的 seo 友好 URL。我几乎在那里并重写了所有链接。但是当涉及到 301 将旧 URL 重定向到新 URL 时,我被卡住了。下面是我是如何做到的。

RewriteEngine On
RewriteRule ^video_gallery video_gallery.php
Redirect /video_gallery.php http://site.com/video_gallery

如上所示,我已将 video_gallary.php 重写为 video_gallary,现在我想将所有带有 http://site.com/video_gallery.php 的请求重定向到 http://site.com/video_gallery 但它现在如上所述正常工作。请在这里帮忙。

谢谢

【问题讨论】:

    标签: .htaccess url-rewriting


    【解决方案1】:

    这将导致重定向循环。您需要匹配 %{THE_REQUEST} 变量,这是实际请求,而不是 URI(在处理过程中会更改)。所以用你的例子:

    RewriteEngine On
    
    RewriteRule ^video_gallery video_gallery.php
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /video_gallery\.php
    RewriteRule ^ /video_gallery [L,R=301]
    

    【讨论】:

      猜你喜欢
      • 2011-10-28
      • 2016-09-28
      • 2013-01-27
      • 2013-12-21
      • 2015-03-04
      • 2015-09-06
      • 2013-03-14
      • 1970-01-01
      • 2023-03-25
      相关资源
      最近更新 更多