Forum Moderators: phranque

Message Too Old, No Replies

htaccess code for 301 redirect: need help

wordpress, 301

         

pro101

6:52 pm on Feb 7, 2009 (gmt 0)

10+ Year Member



Hi all: I've recently discovered that using /%postname%/ only for permalinks on Wordpress posts 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.

I need to redirect from:
[domainname.com...] to [domainname.com...]

I believe I need to make changes to the htaccess file and add a re-direct, from /%postname%/ to /%post_id%/%postname%/. Any idea how to do this? First time trying to do such a thing. The re-direct will need to only apply to posts, not pages.

My current htaccess file looks like this:
# BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
=====================

Any clues on line of code that will do the trick will be much appreciated!

g1smd

7:51 pm on Feb 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There is no way for .htaccess to deduce the value for post_id when a user requests a URL with post_name in it.

This has to be a job for your PHP script as it will need to look things up in the database before it issues the redirect using the PHP HEADER command.