2

我正在寻找重定向的方法

/threads/2486-dell-inspiron-545-grafikkarte-austauschen/3page

threads/2486-dell-inspiron-545-grafikkarte-austauschen/page3

我一直在开始写规则,但我不确定这样做是否正确

RewriteRule ^threads/([0-9]+)-([a-zA-Z0-9_-]+)/$page  /threads/$1-$2/page$3 [R,L]
4

3 回答 3

1

你非常接近,你只需要修改你的正则表达式。

使用 mod_alias:

RedirectMatch 301 ^/threads/([0-9]+)-([a-zA-Z0-9_-]+)/([0-9]+)page$ /threads/$1-$2/page$3

或使用 mod_rewrite:

RewriteRule ^/?threads/([0-9]+)-([a-zA-Z0-9_-]+)/([0-9]+)page$ /threads/$1-$2/page$3 [L,R=301]

请注意,您需要将重写规则置于 htaccess 文件中可能拥有的任何其他路由规则之上,因为您希望在处理或路由 URI 之前应用此规则。此外,如果您混合使用 mod_alias 重定向和 mod_rewrite 路由,您可能只想坚持使用 mod_rewrite。

于 2012-09-20T15:20:34.363 回答
0

尝试

Redirect 301 /threads/2486-dell-inspiron-545-grafikkarte-austauschen/3page /threads/2486-dell-inspiron-545-grafikkarte-austauschen/page3
于 2012-09-20T10:45:14.523 回答
0

您没有创建第三组,请尝试以下操作:

RewriteRule ^/threads/([0-9]+)-([a-zA-Z0-9_-]+)/([0-9]+)page  /threads/$1-$2/page$3 [R,L]

试图更广泛

RewriteRule ^(.+?)/threads/([0-9]+)-([a-zA-Z0-9_-]+)/([0-9]+)page  $1/threads/$2-$3/page$4 [R,L]

此处正则表达式正在工作,请注意/已转义。

于 2012-09-20T10:46:59.607 回答