2

我有以下网址

1) domain.com/articles/one-two-three
2) domain.com/articles/four-five-six
3) domain.com/articles/{name of a post}
4) domain.com/articles/wp-content/
5) domain.com/articles/wp-admin/

我想重定向 URL 1、2 和 3,但不是 4 和 5。换句话说,我想重定向/articles/目录中不以开头的所有页面wp-

以下代码段将重定向之后的所有内容/articles/

Options +FollowSymlinks
RewriteEngine on
# RedirectMatch 301 /articles/(.*) http://domain.com/$1

如何过滤此重定向匹配以排除模式?

编辑回应一些评论

您正在测试的输入 URL(来自浏览器)是什么,

http://www.chipkin.com/articles/steam-boilers-vs-hydronic-boilers/

什么是预期的输出?

http://www.chipkin.com/steam-boilers-vs-hydronic-boilers/

由于这似乎是 WordPress,请在 .htaccess 中发布您可能已经拥有的任何其他规则,因为可能存在冲突。

RewriteEngine On
# If the request doesn't start /articles/wp-
RewriteCond %{REQUEST_URI} !^/articles/wp-
# Rewrite it:
RewriteRule ^articles/(.*) http://www.chipkin.com/$1 [L,R=301]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
4

1 回答 1

2

而不是 a RedirectMatch,使用 aRewriteCond来验证 URI 不以/articles/wp-并执行重写:

RewriteEngine On
# If the request doesn't start /articles/wp-
RewriteCond %{REQUEST_URI} !^/articles/wp-
# Rewrite it:
RewriteRule ^articles/(.*) http://domain.com/$1 [L,R=301]
于 2013-03-21T19:37:09.610 回答