【问题标题】:Is there a way to rewrite just a directory, so that all articles within that directory redirect 1 level up?有没有办法只重写一个目录,以便该目录中的所有文章重定向 1 级?
【发布时间】:2012-10-20 13:46:57
【问题描述】:

我有一个站点http://www.mysite.com/blog/category/post/,我需要将它重定向到http://www.mysite.com/category/post,即我想从我的URL 中删除blog。有没有办法在 .htaccess 中使用永久重定向?

非常感谢!

【问题讨论】:

    标签: regex .htaccess mod-rewrite redirect


    【解决方案1】:

    通过httpd.conf启用mod_rewrite和.htaccess,然后把这段代码放到你.htaccessDOCUMENT_ROOT目录下:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^blog(/.*|)$ $1 [L,R=301,NC]
    

    【讨论】:

      猜你喜欢
      • 2020-12-20
      • 2012-07-14
      • 2013-12-07
      • 1970-01-01
      • 2012-04-09
      • 2014-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多