Your regular expression has the following problems:
- 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.
- 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]+)
- 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.
- The
.
in .html
matches any character, not just a literal period. You should escape the .
in this place: \.html
- 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
- 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.