.htaccess RedirectMatch 301模式

时间:2017-09-24 05:48:33

标签: .htaccess redirect mod-rewrite

我想要在.htaccess中重定向三种模式。

  1. https://example.com/questions/name-of-question
  2. https://example.com/category/name-of-category
  3. https://example.com/a-4-digit-number/name-of-post
  4. (第3号,如:https://example.com/5485/name-of-post

    他们所有人都需要一个/ blog /域名之后:

    1. https://example.com/blog/questions/name-of-question
    2. https://example.com/blog/category/name-of-category
    3. https://example.com/blog/a-4-digit-number/name-of-post
    4. 我使用下面的代码作为第一个,一旦它工作,然后发生了一些事情,htaccess被删除了。现在我使用它againg它不重定向:

      RewriteEngine on
      Options +FollowSymLinks
      RedirectMatch 301 https://example.com/questions/(.*) https://example.com/blog/questions/$1
      

      任何人都可以帮我解决这些重定向问题吗?特别是没有。 3带有4位数字图案。

1 个答案:

答案 0 :(得分:1)

使用RewriteRule这样的指令将所有3条规则定位到一个模式中

Options +FollowSymLinks
RewriteEngine on

RewriteRUle ^/?(questions|category|\d{4})/.+$ /blog/$0 [L,NC,R=301,NE]
相关问题