Redirecting URL by Apache

Create a .htaccess file in the directory where you want to perform the task. These settings will be applicable to sub-directories also 😉

in the .htaccess file, type the following:
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/([^/]+)/([0-9]+)\.html$ /index.php?maindirectory=$1&subdirectory=$2&articleID=$3

The first set of parentheses will equal your first variable “$1”, the second set of parentheses will equal your second variable “$2”, etc.

The following example will not actually work because of the regular expressions however I’m putting it in here for example:

(.*)/(.*)/(.*) = $1/$2/$3

Side-Note: the reason the above example would fail with the regular expression is that the first (.*) will grab everything including the “/”. That is why I used ([^/]+) in the real example, it says grab everything but “/”.