htaccess Redirect - Help

by AgentK
8 replies
I have over 2000+ wordpress posts with the following URL structure

site.com/ID/POST-TITLE

I need to redirect each post to a custom script that uses the wordpress ID:

site.com/post.php?id=ID

If someone could shed some light on this I will love you forever!
#htaccess #redirect
  • Profile picture of the author Fadiz
    I'm not sure if this what you looking for but you can change it back to the default wp urls

    Using Permalinks « WordPress Codex
    {{ DiscussionBoard.errors[7567371].message }}
    • Profile picture of the author AgentK
      Originally Posted by Fadiz View Post

      I'm not sure if this what you looking for but you can change it back to the default wp urls

      Using Permalinks « WordPress Codex
      Thanks for the link but I am migrating from Wordpress over to a custom script and I need my wordpress URLs to be redirected over to the new URLS

      If someone could help me out I would gladly appreciate it.
      {{ DiscussionBoard.errors[7567413].message }}
  • Profile picture of the author Fadiz
    Yeah I figured that wasn't it, you might wanna try stackoverflow.com
    {{ DiscussionBoard.errors[7567621].message }}
    • Profile picture of the author AgentK
      K.

      Thanks for the link.
      {{ DiscussionBoard.errors[7568021].message }}
  • Profile picture of the author Big Squid
    Here you go. Just change the $site variable to whatever you need. This should be included at the very top of the page before anything else.

    If you need any help, let me know...




    <?php
    $site = 'www.site.com'; // change to whatever site you want to redirect to.
    $go = 'http://'.$site.'/post.php?id=';
    $url = parse_url($_SERVER['REQUEST_URI']);
    $path = explode('/', $url['path']);
    $go .= $path[1];

    header('Location: '.$go);
    ?>
    {{ DiscussionBoard.errors[7568794].message }}
  • Profile picture of the author hassan007
    If you are looking for an .htaccess solution then you might need to add every single URL with 301 redirect to the new URL...

    That would be a hectic task though...

    Just search for .htaccess 301 redirect in Google...
    {{ DiscussionBoard.errors[7573610].message }}
  • Profile picture of the author anandshaw
    You will need to do 2 steps
    1) change your permalink to default - after this you should be able to see the WP id for your post in the url
    2) setup .htaccess redirect oldpath to newpath
    ** your post id is available in variable $1
    {{ DiscussionBoard.errors[7577264].message }}
    • Profile picture of the author capsoon
      This Plugin can be help you bro. ^__^

      WordPress › Redirection « WordPress Plugins

      if you want edit htaccess file you can see an example as below


      RewriteCond %{HTTP_HOST} ^newwebsite.com$ [OR]
      RewriteCond %{HTTP_HOST} ^www.newwebsite.com$
      RewriteRule ^archives/1234$ "http://www.newwebsite.com/test-new/" [R=301,L]

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

      # END WordPress
      {{ DiscussionBoard.errors[7599737].message }}

Trending Topics