Go Back   WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk
Register Blogs FAQ Social Groups CalendarHelp Desk

Reply
 
LinkBack Thread Tools
Old 02-07-2009, 02:41 PM   #1
Warrior Member
 
Join Date: Feb 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 301 redirect through PHP in Wordpress

Hi all:

I've recently discovered that using /%postname%/ only for permalinks on posts in Wordpress is not scalable. My site has currently a small number of posts (25) and about 35 pages. Likely I will eventually have 100s of posts, so before it's too late it seems I need to change Permalinks.

Initially tried to look into htaccess rewrite, but Apache experts said that htaccess can't know postid, so the 301 redirect needs to be done through PHP script. I'm looking into PHP files in wordpress and wondering which file (and line of code) I need to change to accomplish this.

Anyone knows what I need to change in wordpress to redirect from:
from domain.com/postname
to domain.com/postid/postname

It would help a lot. Thanks in advance.
pro101 is offline   Reply With Quote
Old 02-08-2009, 01:47 AM   #2
Advanced Warrior
War Room Member
 
Bruce Hearder's Avatar
 
Join Date: May 2004
Location: Perth, Australia.
Posts: 717
Thanks: 4
Thanked 182 Times in 138 Posts
Social Networking View Member's Twitter Profile  View Member's YouTube Profile
Contact Info
Send a message via Skype™ to Bruce Hearder
Default Re: 301 redirect through PHP in Wordpress

Seeing your list of posts is so small (~25), why don't you just manually hard code the redirects into your .htaccess file right now, and then be done with it?

All you will need is a line for each redirect at the top of your .htaccess file that is something like :

redirect 301 /some-old-post-title/ http://www.yourdomain.com/123/some-old-post-title/

That should do it..

Take care

bruce

-----------------
Get Your Backlinks indexed quicker at BackLinks2RSS

Create Full Text Feeds from Partial RSS Feeds at FeedExpander.com. See the WarriorForum post about it here
Bruce Hearder is offline   Reply With Quote
Old 02-08-2009, 08:27 PM   #3
Gleb
War Room Member
 
MemberWing's Avatar
 
Join Date: Dec 2008
Location: Ottawa, Canada
Posts: 845
Thanks: 10
Thanked 104 Times in 85 Posts
Social Networking View Member's Twitter Profile 
Contact Info
Send a message via Skype™ to MemberWing
Default Re: 301 redirect through PHP in Wordpress

Here it goes:
WP Admin panel->Settings->Permalinks -> "Custom Structure" = /%post_id%/%postname%/

Although for SEO friendliness I'd suggest using this:
/%category%/%postname%/

More info here:
Using Permalinks WordPress Codex

Regards,

Gleb Esman

MemberWing is offline   Reply With Quote
Old 02-09-2009, 10:54 PM   #4
Chief Enthusiasm Officer
War Room Member
 
justinkaiser's Avatar
 
Join Date: Feb 2009
Location: Sheldon, IL
Posts: 30
Thanks: 2
Thanked 3 Times in 3 Posts
Social Networking View Member's FaceBook Profile  View Member's Twitter Profile  View Member's YouTube Profile
Contact Info
Send a message via Skype™ to justinkaiser
Default Re: 301 redirect through PHP in Wordpress

I used to use the category/postname as mentioned above. I'd like to return to that configuration but have about 200 posts. Is there an easy way/plugin to do a 301 redirect?

justinkaiser is offline   Reply With Quote
Reply

  WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk

Tags
301, php, redirect, wordpress

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -6. The time now is 04:34 AM.