问题
I have changed my site url structure. But, Google indexed urls are giving 404 not found error. Now, I need a .htaccess rewrite 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.
回答1:
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 +
回答2:
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]
来源:https://stackoverflow.com/questions/5056249/how-to-redirect-rewriten-urls-to-short-urls