I would like to change the structure of the NewMexiKen permalinks. I know how to do that. What I cannot figure out how to do is create the .htaccess rule that will redirect existing permalinks to the new structure.
The current permalink is ^/%year%/%monthnum%/00%post_id%.php
What I want is ^/%year%/%monthnum%/%day%/%postname%/
The existing .htaccess file is:
RewriteRule (^archives/)(.*) $2 [R=301,L]
# BEGIN WordPress
<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</ifmodule>
# END WordPress
My head hurts just from reading that.
Ken- Have you looked at Options > Permalinks, and the Custom option?
That’s how I can change the permalink structure Mark. What I am having trouble with is writing a rule to redirect all the old permalinks to the updated version.
Don’t know if either of these links will help. peace, mjh
[en] .htaccess Editor
http://www.htaccesseditor.com/en.shtml
htaccess Generator
http://cooletips.de/htaccess/
Just saw this now – is this still an issue?
It’s actually not trivial. mod_rewrite does what the name says: it rewrites a url to something else. However in most of the cases it takes what is in the current URL (the incoming one), transposes elements, removes something or adds something to end up with the rewritten URL (the final one). It does not have database access and thus does not know what %postname% is associated with what %post_id%.
That said, there is a way to do if you absolutely insist on having it in place 🙂
mod_rewrite understands the RewriteMap directive. RewriteMap will point to a simply text-file that maps %post_id% to a final URL. Inside the text file each line would contain a number (%post_id%) and a final location. You would have to create this file once for all the old entries.
If you have lots of time on your hand you could also experiment with a prg:-type RewriteMap, which indeed could use a database connection to map %post_id% to perma-link.
Here’s a quick overview of the RewriteMap usage:
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritemap
Let me know if I can help.
The search engines would catch up, but I have a lot of internal links that I would hate to have go bad — and there are by now many external links too. Seems like poor internet etiquette to mess up one’s links on purpose.
That said, I would change them all from post ID to post name if I could preserve the links.
Can you send me two or three examples where a post_id is matched to one of your perma-links? Something like:
00123.php -> /2006/02/14/new-name-of-post
00125.php -> /2006/02/21/another-name
and I’ll try to craft the necessary mod_rewrite statements for you.
You have my email …