Reputation: 11
I recently converted all the .html
pages on my site to .php
. I added the following code to my .htaccess
file:
RedirectMatch permanent ^(.*)\.htm(l?)$ $1.php
This works fine and .html
pages re-direct to .php
pages.
My question is, is there any way to limit what files this code affects?
More specifically I would like to stop the .html
and .htm
pages from my sub domain from being redirected.
shop.domain.com
I have other parts of my website in a sub-directory of the root folder that need to end in .html
and I don't want their .html
extensions to re-direct.
Is there any code or way to do this?
Upvotes: 0
Views: 812
Reputation: 51711
Add this to your .htaccess
in your web root /
directory.
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^shop\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/shop/? [NC]
RewriteRule ^([^/]+)\.html?$ $1.php [R=301,NC,L]
This won't redirect any sub-directory including shop
. In case you want to allow that (except shop
) use
RewriteRule ^(.+)\.html?$ $1.php [R=301,NC,L]
Upvotes: 1