Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 4 down vote accepted

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.

share|improve this answer
geek............ :) +1 – Simon Hayter Mar 20 '13 at 14:22
Thanks, I appreciate that, Simon. :) – Stephen Ostermiller Mar 20 '13 at 14:28
thanks bro pro :) ...but it gave me error 404 page not found fb.manhag.net/redirect/20100417010735/asdasd/… – manhag Mar 20 '13 at 14:48
Start with RewriteRule ^[a-zA-Z0-9_\-]+/ /index.php [L] and build up from there. Use the simplest one that you can get to work and then add pieces. There is a whole thread about debugging rewrite rules at stackoverflow: stackoverflow.com/questions/9153262/… – Stephen Ostermiller Mar 20 '13 at 14:59
I think ^[^/]+/[^/]+/[^/]+/(\d+)-[^\.]+\.html is easier to read and not significantly slower. – toscho Mar 26 '13 at 20:23

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:


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!

share|improve this answer
thanks but the plugin needs regular expression also to redirect all seo url – manhag Mar 20 '13 at 4:53

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]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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