【问题标题】:Redirect everything except one post重定向除一篇文章外的所有内容
【发布时间】:2015-06-09 17:13:19
【问题描述】:

我将这个 htaccess 用于我的 Wordpress 网站,将所有内容重定向到主页。我怎样才能从中排除一个帖子?例如Mysite.com/thank-you

谢谢!

# BEGIN redirect to homepage
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js|php)$
RewriteCond %{REQUEST_URI} !^/wp-admin [NC]
RewriteRule .* / [L,R=301]
#END redirect to homepage

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect


    【解决方案1】:

    将此添加到您的一组条件中:

    RewriteCond %{REQUEST_URI} !^/thank-you/?$ [NC]
    

    与您已经拥有的其他条件非常相似,这个条件表示该规则只有在请求 URI 不以 /thank-you 开头(尾随斜杠可选)时才能生效。

    【讨论】:

    • 如果可能,请解释您的答案,以确保 OP 可以了解更多信息。
    【解决方案2】:

    RewriteEngine On之后添加

    RewriteRule ^thank-you$ - [L]
    

    http://httpd.apache.org/docs/2.4/rewrite/flags.html

    【讨论】:

      【解决方案3】:

      您只需在 htaccess 中添加另一个条件,以防万一它不会重定向感谢页面

      # BEGIN redirect to homepage
      RewriteEngine on
      RewriteCond %{REQUEST_URI} !^/$
      RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js|php)$
      RewriteCond %{REQUEST_URI} !^/thank-you$
      RewriteCond %{REQUEST_URI} !^/wp-admin [NC]
      RewriteRule .* / [L,R=301]
      #END redirect to homepage
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-09-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-24
        • 2010-10-06
        • 2018-01-29
        相关资源
        最近更新 更多