Let's suppose that I have a static website on Apache server with this folders structure:
http://www.example.com
|
+-- /news/
| |
| +-- page1.html
| +-- page2.html
| +-- ...
|
+-- /otherstuff/
http://www.example.com/news/page1.html
http://www.example.com/news/page2.html
http://www.example.com
|
+-- /news/
| |
| +-- /subfolder1/
| | |
| | +-- page1.html
| |
| +-- /subfolder2/
| | |
| | +-- page2.html
| +-- ...
|
+-- /otherstuff/
http://www.example.com/news/page1.html
http://www.example.com/news/page2.html
http://www.example.com/news/subfolder1/page1.html
http://www.example.com/news/subfolder2/page2.html
you can use the following rule in /news/.htaccess :
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/subfolder/$1.html -f
RewriteRule ^(.*?)\.html$ /news/subfolder/$1 [L]
This will rewrite /news/file.html to /news/subfolder/file.html if file.html exists in /news/subfolder/ .
If your htaccess is in root, you can try the following
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/news/subfolder/$1.html -f
RewriteRule ^news/(.*?)\.html$ /news/subfolder/$1.html [L]
If the examples above fail, you can try this in root or news/.htaccess :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?:news/)?(.*?)\.html$ /news/subfolder/$1.html [L]