Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-04-24 08:41:16

Hiram
Member
From: Utrecht, Netherlands
Registered: 2004-02-16
Posts: 35
Website

301 the messy URLs after cleaning them up

I can’t find any instructions on how to manually change all of my old /?id=123 URLs to /squeaky-clean ones using RewriteRules, and fixating them for bots and bookmarks with a nice and firm 301.

I tried:

RewriteRule ^?id=21 /coaching [R=301,L]

but this causes a server error. I tried other things as well, with distressing results. It must be really simple. How does one go about doing this?

Note that I’m not looking for automatic conversion of all URLs in one go; each ?id= URL should be manually redirected to its clean incarnation that has no number in it to match the old messy URL. In other words, I’m simply looking for the correct syntax of the first part of the rule.

Offline

#2 2006-04-24 09:06:32

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: 301 the messy URLs after cleaning them up

RewriteCond %{QUERY_STRING} ^id=22$
RewriteRule .* /coaching? [R=301,L]

The question mark after coaching makes sure that the QUERY_STRING is emptied and does not appear in the url. If you wish to keep the ?id=22 in the query-string (to maybe display a message etc.), you can remove the questionmark.

Offline

#3 2006-04-24 09:08:53

Hiram
Member
From: Utrecht, Netherlands
Registered: 2004-02-16
Posts: 35
Website

Re: 301 the messy URLs after cleaning them up

Thank you, Sencer. Very helpful!

For those making use of this solution, it may be relevant to note that the question mark following the second argument should be omitted when referring to a section, as in:

RewriteRule .* /?s=sectionname [R=301,L]

I don’t know why, but leaving the question mark in place after a section URL causes an error. With URLs referring to a single article, the question mark should be added, and will work as advertised.

Last edited by Hiram (2006-04-24 10:18:49)

Offline

Board footer

Powered by FluxBB