Search code examples
apache.htaccessmod-rewritehttp-redirectmod-alias

301 redirect: selective loss of extension within a directory


I am migrating a site, most pages have page to page 301 redirects - no problem.

There's a directory; http://example.com/associates/ with a whole bunch of individual files; http://example.com/associates/first-last.php

I need to map them to http://example.com/associates/first-last I'm thinking RewriteCond /associates/*\.php -f will find them, what will redirect them?


Solution

  • You can use the following code :

    RedirectMatch ^/associates/([^.]+)\.php$ /associates/$1
    

    ([^.]+) captures any characters excluding a dot, in your case it will capture file name first-last and append it to target url as $1