Reputation: 1751
I have an .htaccess
file that's in my site's root dir with the following rewrite rules meant to remove .html
from the end of urls:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+)\.html\ HTTP/
RewriteRule ^(.+)\.html$ http://example.com/$1 [R=302]
RewriteRule ^([a-z]+)$ /$1.html [L]
</IfModule>
It works on all the pages that are directly within root (example.com/page.html
), but 404s on pages one directory deep (example.com/dir/page.html
). The pages that 404 appear exactly how I'd like them to in the address bar, though (example.com/dir/page
).
I've confirmed that the directory and all its pages do in fact exist in the right places and are properly named. I've also confirmed that this bit of code is the culprit for the 404 (if I remove it, the problem disappears).
So I've been going in and double checking these rules, but I am new to regular expressions and having a really hard time understanding what about this would cause files in child directories to 404. Can anyone help me figure out what's wrong please?
Upvotes: 1
Views: 37
Reputation: 41219
The problem is with your pattern, you need to allow slashes so that it can match the subfolder
RewriteRule ^([a-z/]+)$ /$1.html [L]
Upvotes: 1