Haven't been able to find what I'm looking for in .htaccess QA's on here so forgive me if this is duplicate. I have the following problem with a static HTML site. Structure is below.
My relative paths in info.html
and contact.html
have to use /home/css/style.css
while index.html
uses /css/style.css
. Thanks for help.
Root
- .htaccess
↳ Drupal
- .git
↳ Dev
- .git
↳ Home
- .htaccess
- .git
- css
- js
- img
- info.html
- contact.html
- index.html
Goal
Dev.example.com
to use all the files from/Dev
example.com
to use all the files fromexample.com/home
example.com/info
to redirect fromexample.com/home/info.html
.example.com/contact
to redirect fromexample.com/home/contact.html
.
What I've tried so far
in root .htaccess
# Set a default home directory, (this subfolder always loads)
# RewriteEngine On
# RewriteCond %{THE_REQUEST} ^GET\ /home/
# # RewriteCond %{HTTP_HOST} ^(www\.)?example.com$
# RewriteRule ^home/(.*) /$1 [L,R=301]
# RewriteCond %{HTTP_HOST} ^(www\.)?example.com$
# RewriteRule !^home/ home%{REQUEST_URI} [L]
Options -Indexes
ErrorDocument 404 /missing.html
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
<FilesMatch "\.(htm|html|css|js)$">
AddDefaultCharset UTF-8
</FilesMatch>
RedirectMatch 404 "(?:.*)/(?:\.git|file_or_dir)(?:/.*)?$"
# remove .html from html file names
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*[^/]$ %{REQUEST_URI}/ [L,R=301]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)/$ $1.html [L]
And in Root/drupal .htaccess
default drupal stuff
Closest answers I could find on SO:
- .htaccess rewrite to redirect root URL to subdirectory
- Changing all my website links: what is the best way?
- Redirecting root of site to subdirectory using .htaccess
- htaccess subdirectory URLS to root
EDIT: I ended up following, partially, the advice given because I have separate git repos per subdirectory. Thanks @Jon Lin and @tttony!
New problem: My .htaccess in root doesn't let me view my drupal installation in subfolder.
Drupal.examples.com
uses all the drupal files from/Drupal
**