[wp-hackers] mod_rewrite help

Mike Schinkel mikeschinkel at newclarity.net
Sun Jul 19 05:29:15 UTC 2009


Oops, that one line should have been ($path, not $$path):

  header('Location:' . $url_paths[$path],true,301);

-Mike Schinkel
Custom Wordpress Plugins
http://mikeschinkel.com/custom-wordpress-plugins

----- Original Message -----
From: "Mike Schinkel" <mikeschinkel at newclarity.net>
To: wp-hackers at lists.automattic.com
Sent: Sunday, July 19, 2009 1:26:17 AM GMT -05:00 US/Canada Eastern
Subject: Re: [wp-hackers] mod_rewrite help

Bryan,

Since you have a one-time conversion you could write an add-hoc plugin, or maybe even add the code to your theme's functions.php file and hook "template_redirect"[1] something like this:

add_action('template_redirect','joomla_url_fix');
function joomla_url_fix() {
  $path = $_SERVER['REQUEST_URI'];
  if (preg_match('#^/category/([^-]+)-([^.]+).html$#',$path)) {
    $url_paths = array();
    // Do one line of these for each of your Joomla URLs 
    $url_paths['{joomla_url_path}'] = '{wordpress_url_path}';
    //... 
    if (isset($url_paths[$path])) {
      header('Location:' . $url_paths[$$path],true,301);
      exit();
    }
  }
}

Of course replace {joomla_url_path} and {wordpress_url_path} with the matching URL paths from Joomla and WordPress. Also, I didn't test this code so not sure if the RegEx works or that there's not another bug in it, but hopefully you know enough PHP to get the picture?

Hope this helps. BTW, congrats on graduating from Joomla to WordPress. :)

-Mike Schinkel
Custom Wordpress Plugins
http://mikeschinkel.com/custom-wordpress-plugins

[1] You can out in functions.php in your theme if it is loaded before "template_redirect", but I'm not sure it is.

----- Original Message -----
From: "Bryan Harley" <bryanharley at gmail.com>
To: wp-hackers at lists.automattic.com
Sent: Sunday, July 19, 2009 12:54:01 AM GMT -05:00 US/Canada Eastern
Subject: Re: [wp-hackers] mod_rewrite help

Thanks scribu, but that's not working for me.  And I know exactly why...

My old permalink structure:    /category/post_id-postname.html
My new permalink structure:  /category/post_id/postname/

The problem is the old permalink structure is from Joomla.  Since I
converted the site to WordPress, it's obviously using different ID's
for each post.  Other than that it would work.  This is why I was
pretty sure I'd have to write a mod_rewrite rule rather than just a
plugin.

Any ideas?

Is there anyway to view the mod_rewrite rule that Dean's Permalink
Migration Plugin generates?  If so, I'm pretty sure I could modify it
to make it work.



On Fri, Jul 17, 2009 at 3:31 AM, scribu<scribu at gmail.com> wrote:
> Actually, I think you need this plugin:
>
> http://www.deanlee.cn/wordpress/permalinks-migration-plugin/
>
> It works great on my site.
>
>
> On Fri, Jul 17, 2009 at 2:36 AM, James Collins <james at om4.com.au> wrote:
>
>> Hi Bryan,
>> I would use the redirection plugin (
>> http://wordpress.org/extend/plugins/redirection/) to achieve this.
>>
>> Much easier than modifying your .htaccess file.
>>
>> Regards,
>>
>> James Collins
>>
>> OM4 - Website Design and Development
>> OM4.com.au | OM4Tourism.com
>>
>>
>>
>> 2009/7/17 Bryan Harley <bryanharley at gmail.com>
>>
>> > I have one type of URL that I want to 301 redirect to another.  Can
>> > anyone help me write the mod_rewrite rule that can accomplish this?
>> >
>> > http://www.domain.com/category/postid-post-name.html
>> >
>> > http://www.domain.com/post-name/
>> > _______________________________________________
>> > wp-hackers mailing list
>> > wp-hackers at lists.automattic.com
>> > http://lists.automattic.com/mailman/listinfo/wp-hackers
>> >
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>
>
>
> --
> http://scribu.net
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list