Ben Ben - 3 months ago 35
Apache Configuration Question

.htaccess directory wildcard redirect

Please can someone tell me why this isn't working?

I am trying to redirect all files within the directory "Kent". In this example the page to be redirected is "ramsgate" and change the folder structure.

from:

/electrical-contractors/kent/ramsgate.php


to:

/electrical-contractors-ramsgate/


Using a wildcard redirect, why doesn't this work?

RedirectMatch 301 /electrical-contractors/kent/(.*).php /electrical-contractors-$1/

Answer

Have this rule inside /electrical-contractors/kent/.htaccess:

RewriteEngine On

RewriteRule ^(.+)\.php$ /electrical-contractors-$1/ [L,NC,R=301]
Comments