通用URL重写和301重定向

时间:2014-05-01 13:34:34

标签: apache .htaccess mod-rewrite redirect

我用代理

编写了apache mod_rewrite
RewriteRule ^(.*)/birthday-bengaluru  $1/birthday/bengaluru [R,P,NC]

如果我想再像Newyork那样做一个城市再想写一行像

那样
RewriteRule ^(.*)/birthday-newyork  $1/birthday/Newyork [R,P,NC]

无论如何我们可以像这样写

RewriteRule ^(.*)/birthday-(.*)$  $1/birthday/$1 [R,P,NC]

感谢 Mahesha M

1 个答案:

答案 0 :(得分:0)

您的重定向似乎有一个小类型。在RewriteRule中,您可以使用$ 1访问第一个括号的内容,使用$ 2访问第二个括号的内容(依此类推)。您在规则RewriteRule ^(.*)/birthday-(.*)$ $1/birthday/$1 [R,P,NC]中使用两次$ 1,因此这将从

进行重定向

http://domain.com/birthday-bengaluru

http://domain.com/birthday-http://domain.com/birthday

重写规则应如下所示:

RewriteRule ^(.*)/birthday-(.*)$  $1/birthday/$2 [R,P,NC]
相关问题