开发者

rewrite url as search query

I recently changed domains and the new site has a different permalink structure. Instead of redirecting everything from the old site to the new one, I'd like to set up .htaccess to rewrite the old URL as query stri开发者_StackOverflow社区ng so that the requested page can be found without having to type it into the search of the new site.

For example:

www.oldsite.com/projects/2010/foo-bar-foobar should redirect to www.newsite.com/?s=foo+bar+foobar

The old permalink structure always starts with a year (4 digits), the new structure is completely different so I think redirecting to a search query would be the best bet.

I tried to get my head around regex but I just can't get anywhere near a solution that works.

I hope someone can point me in the right direction.

Thanks!


I always screw these up the first time, but you can try this (in the .htaccess on www.oldsite.com):

RewriteRule ^/?projects/[0-9]+/(.*)$ http://www.newsite.com/?s=$1 [R]

In english, this matches a URL on the old site that starts with an optional slash, followed by the word "projects," then another slash, then one or more digits, then a slash, then any number of characters. It redirects to the newsite, passing that last group of "any number of characters" as the query string. The last "R" tells the rewrite engine to issue a redirect to the user-agent.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜