0

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.

CloudyMarble
  • 36,908
  • 70
  • 97
  • 130
user625118
  • 29
  • 1
  • 6

2 Answers2

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 +

Shaun Hare
  • 3,771
  • 2
  • 24
  • 36
  • as per edit if the hyphen is there also would need to add that to the second group do you know exact number of digits in id? – Shaun Hare Feb 20 '11 at 10:03
  • Actually, the pages starts like 273.html, after five posts, the second page 273-5.html, third page 273-10.html and so on. I need to redirect all those indexed pages to be redirected to – user625118 Feb 20 '11 at 10:06
  • I see no change! Nothing happens. Same 404 not found. – user625118 Feb 20 '11 at 10:31
  • Sorry, The problem came because of some numbers present in url title text I tested, like www.mydomain.com/topic-51-titles-here-t273-15.html. – user625118 Feb 20 '11 at 10:44
  • But, now also I'm getting another error: "Firefox has detected that the server is redirecting the request for this address in a way that will never complete." Checked url has no numbers in it's title text. – user625118 Feb 20 '11 at 10:45
  • Ok if there are numbers in topic you can use t(\d{3}-\d+\.html) that will just match the last part in the first example specifically and may help the redirect not getting hit again – Shaun Hare Feb 20 '11 at 10:48
  • Again sorry, I added both the codes, that is the reason for firefox error. Ok, but, can you tell the answer for the urls with numbers in them, like www.mydomain.com/topic-51-titles-here-t273-15.html. Please. – user625118 Feb 20 '11 at 10:48
  • Can't find any use with t(\d{3}-\d+\.html). Now, urls without numbers in topic titles are working fine, But, those with numbers are giving 404. – user625118 Feb 20 '11 at 11:03
  • I checked and rechecked. It's working only if I hit tryagin button. As I couldn't post entire code here I posted it as a different question: http://stackoverflow.com/questions/5057164/how-to-redirect-static-urls-to-small-urls – user625118 Feb 20 '11 at 13:21
  • Finally I found solution: `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]` Anyhow, thankyou verymuch Shaun Hare. – user625118 Feb 20 '11 at 13:57
0
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]
user625118
  • 29
  • 1
  • 6