开发者

How to redirect - rewriten urls to short urls

I have changed my site url structure. But, Google indexed urls are giving 404 not found error. Now, I need a .htaccess rewr开发者_如何学JAVAite rule for,

From url: www.mydomain.com/topic-titles-here-t273.html

To url: www.mydomain.com/sub-folder/topic273.html

(Topic id must be cached and topic title must be removed.)

Some times, like this also,

From url: www.mydomain.com/topic-titles-here-t273-15.html

To url: www.mydomain.com/sub-folder/topic273-15.html

I searched a lot, for about three hours, But couldn't find correct answer. Please help.


I am a little unclear on what you are trying to do but

1

RewriteRule    ^([a-z|-]+)(\d+\.html)$    /sub-folder/topic$2    [NC,L]  

Would take the second group (just 273.html) and append accordingly, the first group would be everything before (topic-titles-here-t)

is that what you require? If so the regex could be tidied I just wanted to demonstrate the two groups

update - Ok according to edit the second group just becomes

(\d{3}-\d+\.html)

if 273 used in this example can be longer than 3 nubers if you know exact just amend that number otherwise use +


RewriteRule ^([a-z0-9|-]+)t(\d+\.html)$ /redirect/topic$2 [NC,R=301,L]
RewriteRule ^([a-z0-9|-]+)t(\d+-\d+\.html)$ /redirect/topic$2 [NC,R=301,L]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜