【发布时间】:2013-10-21 15:18:47
【问题描述】:
无法在此处的 .htaccess QA 中找到我要查找的内容,如果重复,请见谅。我在静态 HTML 网站上遇到以下问题。结构如下。
我在info.html 和contact.html 中的相对路径必须使用/home/css/style.css,而index.html 使用/css/style.css。感谢帮助。
Root
- .htaccess
↳ Drupal
- .git
↳ Dev
- .git
↳ Home
- .htaccess
- .git
- css
- js
- img
- info.html
- contact.html
- index.html
目标
-
Dev.example.com使用来自/Dev的所有文件 -
example.com使用来自example.com/home的所有文件 -
example.com/info从example.com/home/info.html重定向。 -
example.com/contact从example.com/home/contact.html重定向。
到目前为止我所做的尝试
在根 .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]
并且在 Root/drupal .htaccess 中
default drupal stuff
我可以在 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
编辑:我最终部分遵循了给出的建议,因为每个子目录都有单独的 git 存储库。谢谢@Jon Lin 和@tttony!
新问题:我在根目录下的 .htaccess 不允许我在子文件夹中查看我的 drupal 安装。
-
Drupal.examples.com使用来自/Drupal的所有drupal文件**
【问题讨论】: