blackbull77
blackbull77

Reputation: 379

.htaccess php to html only in root

I been using .htaccess to change php to html and it works great, but I hit a snag when I forgot that some of my static html pages in subfolders don't appear in the web browser.

Is there a way I can make it so I can only have the root folder uses the .htaccess rule and not the subfolders?

RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.html$ $1.php [L] 

Upvotes: 1

Views: 828

Answers (2)

anubhava
anubhava

Reputation: 785276

For this case define your .htaccess rule like this:

Options -MultiViews +FollowSymLinks
RewriteEngine On

RewriteRule ^(?![^/]+/)(.+)\.html$ $1.php [L]

Negative lookahead will prevent sub directory rule implementation.

Upvotes: 1

David Rodrigues
David Rodrigues

Reputation: 12532

You can specific a rule to work only on current dir. Like:

/your/dir/here/.htaccess

You .htaccess will be:

RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\/here(.*)\.html$ $2.php [L]

$2 mean get second group.

Edit: alternativaly, you can make a .htaccess on subfolder and disable RewriteEngine.

Upvotes: 0

Related Questions