4

I am trying to migrate from Joomla 1.5 SEF URL's to WordPress SEF URL's.

  1. The old links use this formatting: /site/sectionname/categoryname/id-titlename.html

  2. I want to migrate it to /wp/index.php?p=id

I have modified my .htaccess file but it doesn't seem to work.

RewriteEngine on
RewriteRule ^/(.*)/(.*)/[0-9]+-(.*)$ /index.php?p=$3 [L]

Does anyone have an idea how I can resolve this issue.

4

Your regular expression has the following problems:

  1. It only has .* for the "site" and "sectionname", but is missing one for the "categoryname". Based on your example, there should be a third directory level in your regex.
  2. You have parenthesis around items which you don't need to reference, but no parenthesis around the ID, which you will need to reference. You should remove all the parenthesis that are currently in there regex, and put some around the id: ([0-9]+)
  3. It would be better to use a character class rather than .*. The dot is greedy and will match everything including the following slash. A regular expression written with multiple .*s in it will require the regular expression engine to do lots of extra "back tracking" work. The regular expression will not perform as well as it should.
  4. The . in .html matches any character, not just a literal period. You should escape the . in this place: \.html
  5. If this rewrite rule is meant for .htaccess, the regular expression should not start with a slash, the starting slash is assumed in the context of .htaccess. Rewrite rules should only start with / when they go in httpd.conf
  6. If you want your rewrite rule to redirect rather than show the contents at the existing URL, you should change [L] to [L,R=301]

Here is a regular expression that may work better for you. This assumes that only letters, numbers, underscores and dashes can appear in categories, titles, and such.

RewriteEngine on
RewriteRule ^[a-zA-Z0-9_\-]+/[a-zA-Z0-9_\-]+/[a-zA-Z0-9_\-]+/([0-9]+)-[a-zA-Z0-9_\-]+\.html /index.php?p=$1 [L]

You could also try putting this regular expression in the redirection plugin mentioned in Timothy's answer.

4

If you are using Wordpress now, and simply trying to redirect old Joomla urls to your new urls I suggest using a plugin to make your life easier.

I recommend this plugin a lot:

http://wordpress.org/extend/plugins/redirection/

Also keep in mind that you should use fancy permalinks within Wordpress instead of the standard ID numbers. You can find this setting in the Settings options in wp-admin!

  • thanks but the plugin needs regular expression also to redirect all seo url – manhag Mar 20 '13 at 4:53
1

I think you could resolve this specific issue by modifying your Rewrite rule a little bit to capture the post id and pass it on. Currently, you are passing in the post title, when you should pass the id.

RewriteEngine on
RewriteRule ~/.*/.*/([0-9]+)-.*$ /index.php?p=$1 [L]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.