Apache Rewrites using .htaccess on FreeBSD

Edit httpd.conf and uncomment this line:

#LoadModule rewrite_module libexec/apache24/mod_rewrite.so

In the web root directory create the .htaccess file and open it with an editor:

nano /usr/local/www/apache24/data/.htaccess

Add the following to the newly created .htaccess file:

RewriteEngine On
RewriteBase /
#1) externally redirect "/file.html" to "/file"
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R=301,L]
#2) rewrite  "/file" back to "/file.html"
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*?)/?$ $1.html [NC,L]

Leave a Reply

Your email address will not be published. Required fields are marked *

WordPress Appliance - Powered by TurnKey Linux