从.htaccess文件重定向的URL

时间:2014-07-28 09:38:48

标签: .htaccess drupal-7

如何重定向格式的网址

www.example.com/movies/[anything]/[anything]/[string].html
www.example.com/tv/[anything]/[anything]/[string].html
www.example.com/videogame/[anything]/[anything]/[string].html

www.example.com/redirect/movies/[string]
www.example.com/redirect/tv/[string]
www.example.com/redirect/videogame/[string]

2 个答案:

答案 0 :(得分:2)

您可以将此规则放在root .htaccess中:

RewriteEngine On
RewriteBase /

RewriteRule ^([^/]+)/[^/]+/[^/]+/([^.]+/)\.html$ $1/$2 [L,NC,R]

答案 1 :(得分:0)

在@anubhava的帮助下,这就是我最终的目标。

RewriteEngine On
RewriteBase /
 RewriteRule ^movies/([A-Za-z-]+)/([A-Za-z-]+)/([A-Za-z0-9-]+)\.html$  redirect/movies/$3 [L,NC,R]
 RewriteRule ^tv/([A-Za-z-]+)/([A-Za-z-]+)/([A-Za-z0-9-]+)\.html$  redirect/tv/$3 [L,NC,R]
 RewriteRule ^videogame/([A-Za-z-]+)/([A-Za-z-]+)/([A-Za-z0-9-]+)\.html$  redirect/videogame/$3 [L,NC,R]