Welcome to WebmasterWorld Guest from 3.227.233.78

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

301 Redirect some subfolders but not all

I need to try and redirect certain ones

     
7:35 pm on Jan 30, 2015 (gmt 0)

Full Member

10+ Year Member

joined:July 6, 2005
posts:316
votes: 19


Hey Folks,

I don't post here often but stuck on this one.

Last year switched our site from our custom CMS to Wordpress. But i did not import older stuff as hundreds of thousands of articles...entertainment news site online or 10 years+ so lot of stuff.

Anyway, we also have lots of entries for people and I do want to import them. However, i can only automate import of certain parts and will have to do the images manually.

So I want to do the import. Then redirect

/people/Person_Name/
/people/Person_Name/Biography/

both to

/celebrities/person-name/


I want to exclude at first and later redirect this folder and all files below it

people/Person_Name/pictures/

to

/person-name-pictures/

So I can see how I might 301 a wildcard to redirect all the /people/

But is there a way to do what I want with excluding pictures/ at first.

Also is there a way I can redirect without the capitalisation in the old URLs or will that not matter as the new page lowercase?

Sorry if not explained very well.

Essentially I want to redirect
/people/*/
/people/*/biography/

but not folder/*/pictures/


I can't do them manually as about 7000.

Thanks
James
9:17 pm on Jan 30, 2015 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15889
votes: 876


But is there a way to do what I want with excluding pictures/ at first.

Yes, that's straightforward. WP is built around mod_rewrite. So everything you need to add should go in your htaccess immediately before the WP section (the part that begins and ends in #comment lines).

The RewriteRule that creates your redirect will need a preceding condition that says something like

RewriteCond %{REQUEST_URI} !/pictures/


without anchor.

Also is there a way I can redirect without the capitalisation in the old URLs or will that not matter as the new page lowercase?

This part is trickier. There is undoubtedly something in WP that changes casing, and maybe also something that replaces _ lowline with - hyphen. You may need to add a plugin or check a box somewhere; see the WP subforum for details. But that's a pretty server-intensive approach.

Since it isn't your own server, you do not have the option of using Apache's built-in case-changing RewriteMap function. (That is: you probably can't do it. You can use a RewriteMap in htaccess-- but only if it has been defined in the config file. Your host probably hasn't taken this extra step, because why would they. Mine doesn't; I asked once.)

That leaves two other routes.

One option is to rewrite (not redirect) to a php script that does all the replacing and case-changing in one fell swoop and issues a redirect at the end. Now, you did say you formerly had a hand-rolled CMS. This means that possibly somebody in your organization speaks php, and they could run up such a php script in about five minutes. (That is, about five programming minutes, translating to no more than an hour as measured on the clock.)

The second option is to make a whole bunch of RewriteRules, one for each letter of the alphabet, and string them together with [N] flags (omitting [L]). I do not recommend this approach unless your name is J.D. Morgan. Even the Apache docs say
Use with extreme caution