I have this folder structure:
/fonts /myfont.eot /myfont.svg /myfont.ttf /myfont.woff /myfont.woff2 /content /page1 /files /logo.png /style.css /index.html /page2 /files /logo.png /style.css /index.html /page3 /files /logo.png /style.css /a /index.html /b /index.html ... The URLs one would call look like this:
example.com/content/page1example.com/content/page2example.com/content/page3/aexample.com/content/page3/b
Now all I want to achieve with an .htaccess file located in /page3 is that whoever visits example.com/content/page3 is properly redirect to example.com/content/page3/a (or example.com/content/page3/a/index.html, I don't mind whether the file name is in the URL or not).
I tried
DirectoryIndex /content/page3/a/index.html but in this case when I open example.com/content/page3 all relative references in the /a/index.html file are broken because of the missing directory level in the URL. Furthermore, while calling example.com/content/page3/a works, example.com/content/page3/b gives 403 Forbidden.
I tried
Redirect 301 /content/page3 /content/page3/a but this obviously results in an endless redirect spiral to example.com/content/page3/a/a/a/a/a/a/...... until the server stops trying.
So I figured I need some RedirectCond and RedirectRule configuration. Unfortunately, I don't understand the syntax, and all examples I looked at are doing it on the top-level with more complex stuff like redirecting files and sub-folders, sometimes off to another domain etc.
I tried this
RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ RewriteCond %{REQUEST_URI} ^/content/page3/$ RewriteRule ^/content/page3/?$ /content/page3/a [L] because I figured this would replace "/content/page3" with "/content/page3/a", but to no avail, it doesn't do anything.
I now went with using
DirectoryIndex /content/page3/a/index.html index.html and replaced the relative references in the document with absolute ones. This works.
But firstly I would still prefer if the references could remain relative, so the document doesn't break in case the page3 folder is ever renamed, and secondly I'd rather have the /a subdirectory in the URL for clarity as to what is displayed.
How can I achieve this?