Jay
Jay

Reputation: 312

Add .html extension to slug

On this post: htaccess add .html extension for urls with or without trailing slash I got 99% of the solution for re-writing slug to .html extension. My question is, is it also possible to make http://domain.com dynamic?

The index.php may or may not be running on a sub-directory (IE. test/index.php).

The code on the mentioned post is:

RewriteEngine on
Options +FollowSymLinks
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-l
RewriteRule ^(([\w/-]+)?[\w-])/?(?!:\.html)$ http://domain.com/$1.html [L,R=301]
RewriteRule ^(([\w/-]+)?[\w-])\.html$ test/index.php?slug=$1 [L]

PS: %{HTTP_HOST} doesn't seem to do the trick.

Upvotes: 0

Views: 345

Answers (1)

anubhava
anubhava

Reputation: 785128

This should work by removing host part from target URI:

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-l
RewriteRule ^(([\w/-]+)?[\w-])/?(?!:\.html)$ /$1.html [L,R=302,NC]

RewriteRule ^(([\w/-]+)?[\w-])\.html$ admin/index.php?slug=$1 [L,QSA,NC]

Make sure you clear your browser cache before testing this and there are no other rules.

Upvotes: 1

Related Questions