为什么我的RewriteRule不起作用?正则表达式匹配

时间:2014-12-01 15:43:49

标签: apache .htaccess http mod-rewrite

网址应该

from: http://myurl.com/anything/?_escaped_fragment_=/article/1234
  to: http://myurl.com/rubriken/detail/articleuid/1234/

我的RewriteRule看起来像:

RewriteRule ^.*\?_escaped_fragment_=\/article/(.*)$ /rubriken/detail/articleuid/$1/ [R=301,L]

我在http://regex101.com/上测试了正则表达式并且它匹配。但它在我的.htaccess中不起作用,也不在http://htaccess.madewithlove.be/上起作用。我的错误在哪里?

1 个答案:

答案 0 :(得分:2)

因为RewriteRule中没有使用?_escaped_fragment_=/article/1234

使用:

RewriteCond %{QUERY_STRING} _escaped_fragment_=/article/(.*)$
RewriteRule ^ /rubriken/detail/articleuid/%1/? [R=302,L]

当测试工作正常时,更改[R=302,L] [R=301,L]