This forum is in permanent archive mode. Our new active community can be found here.

.htaccess files and redirects

edited February 2007 in Everything Else
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

  • You're going to need to learn regular expressions, and you're going to have to write the .htaccess file by hand.
  • Regular expressions aren't that difficult to use, but you need to have a strong grasp of logic and a good eye for syntax.

    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 have been expecting to have to hand code in redirects for every blog entry, I've already resigned myself to it!

    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 have been expecting to have to hand code in redirects for every blog entry, I've already resigned myself to it!

    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.
    You won't have to hand-code every redirect if you use regular expressions.
  • edited February 2007
    http://httpd.apache.org/docs/1.3/mod/mod_alias.html#redirect

    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.
    Post edited by Alex on
  • Since I can't get this to work I'm just going to cheese out and change the index.php page into a redirect that takes the argument and pulls a redirect page out of the db and sends the user on their way.
  • <?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.
  • Personally, I think you're reinventing the wheel. Apache provides tools to do this sort of thing, which have been vetted by thousands of sites over many years. I don't know what you think you're gaining by reimplementing part of those tools in PHP.

    But it's your website.
  • I can't use a redirect because the file being redirected is index.php and I can't get it to also pass the argument that comes after the "?".

    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.
Sign In or Register to comment.