.htaccess files and redirects
I'm hoping someone on here with more knowledge than I can help me out.
I'm in the middle of moving my blog from a serendipity install to a wordpress install and I need to write some redirects into my .htaccess file. The problem I have is that it is not working.
old URL -> www.hmtk.com/blog/index.php?/archives/[postID]-[postname].html
new URL -> www.hmtk.com/[postID]-[postname].html
I had first tried to exactly match the URLs but WP chokes on the "?" as it implies an option.
I also tried writing it exactly (one for one)
redirect
http://www.hmtk.com/[old post]
http://www.hmtk.com/[new post]
but it kept sending ALL old links to my blog index and not the individual post.
help?
Comments
Don't worry about learning to use them natively: just learn how to use them at all. You can always use reference materials to look up the details while you're working.
I just can't figure why the one attempt I made using the redirect sent the request to the index page and not the post page... I thought the redirect would look for exact matches.
I presume you've read the above, or the equivalent for whatever version of apache you're using. Do so if you haven't.
My first guess, though, would be that one or more of the argument URLs should be relative to your document root, rather than absolute. ("/blog" rather than "http://www.hmtk.com/blog")
EDIT: You also might consider using mod_rewrite instead of redirects, thus taking advantage of regular expressions as suggested above.
<?php
$page = basename($_SERVER['QUERY_STRING']);
$page = str_replace(',', '', $page);
$page = str_replace('+', '', $page);
$page = str_replace('!', '', $page);
$page = str_replace('?', '', $page);
$new_url = "http://www.hmtk.com/archives/" . $page;
header("Location: $new_url");
?>
I'm going to use this quick php hack.
But it's your website.
If I try to redirect "index.php?/something" only index.php gets redirected and the trailing argument "/something" is ignored. I spent three days trying to do this with a redirect and it just will not work.
I can't use mod_rewrite because I'm not rewriting URLS but redirecting them.