0

trying to rewrite URL strings only for pages that reside in the root, removing the page extension for cosmetic reaons. For example:

www.site.com/page.html ==> www.site.com/page www.site.com/about.html ==> www.site.com/about

Using this code currently:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.]+\.com) [NC]
RewriteRule (.*) http://www.%1/$1 [R=301,L]

BUT, I don't want the rule to modify sub-directiories or sub-domains. For example I also have:

clientA.site.com (which is mapped to www.site.com/clientA), which I need to not be remain unchanged. Right now it is sending that page (client.site.com/index.html) to a page not found.

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
J R
  • 1

1 Answers1

0

Your rule doesn't affect subdomains. There must be other rules causing the 404 not found response.

If you want to restrict requests to the root pages, you can specify that with an appropriate pattern by excluding slashes in the request URL path

# exclude directories
RewriteCond %{REQUEST_FILENAME} !-d
# allow top level request URLs only
RewriteRule ^[^/]*$ http://www.%1/$0 [R,L]

Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.

Community
  • 1
  • 1
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198