Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-10-17 14:28:58

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,356
GitHub

[SOLVED] Changed article section, using .htaccess to redirect

I’ve changed the article section for a bunch of old articles. I am now, inevitably dealing with the sitemap and search engine 404 error fallout. Assume I’m switching articles from this format:

http://example.com/old/article-title

…to this:

http://example.com/new/article-title

My .htaccess regex voodoo isn’t as good as it used to be. I’m using the following as a base:

RewriteEngine on
RewriteRule ^old(/.*)?$ /new$1 [L,R=301]

Somewhat predictably, it’s not working. My humble request is two-fold:

i) What am I doing wrong with my code above?
ii) Where is the best place for the code to be situated, assuming a stock .htaccess with the standard Rewrite rules?

As ever, thank you in advance for pointers and advice.

Last edited by gaekwad (2013-10-17 15:35:03)

Offline

#2 2013-10-17 15:27:19

alivato
Member
Registered: 2011-03-31
Posts: 151

Re: [SOLVED] Changed article section, using .htaccess to redirect

Try this

RedirectMatch 301 ^/old/(.*)$ http://www.example.com/new/$1

Offline

#3 2013-10-17 15:32:24

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,356
GitHub

Re: [SOLVED] Changed article section, using .htaccess to redirect

Oh, smart – thanks, alivato.

Offline

#4 2013-10-17 15:34:49

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,356
GitHub

Re: [SOLVED] Changed article section, using .htaccess to redirect

OK, solved: my syntax was correct, but the placement was wrong. Having it as the first condition after RewriteEngine On makes it work; I had it too low in the file and it was being shoved out.

Thanks again to alivato for a potentially prettier solution.

Offline

Board footer

Powered by FluxBB