【问题标题】:Change ROOT folder directory更改ROOT文件夹目录
【发布时间】:2021-09-04 00:35:36
【问题描述】:

我想将根文件夹目录从 www.example.com/index.html(基本目录)更改为子目录 www.example.com/dist/index.html 并充当 www.example.com strong> 使用 .htaccess 规则

【问题讨论】:

  • Thanx @ftrsk 但这个答案对我不好......使用重定向,我想用新目录重写或替换原始目录
  • 您能说明一下您要解决的问题吗?比如,为什么你希望默认资源来自 web 根目录的子目录?为什么不直接更改网络根目录?
  • @DonR:这真的重要吗?可以独立于他们的特定业务需求为何需要此功能来回答这个问题。
  • @JeremyCaney 可能重要的原因是它不使用重定向的要求让我想知道这是否不是 XY 问题,因为重写也可以通过重定向起作用。我想知道了解大局是否有助于我们想出更好的方法。

标签: apache .htaccess web server routes


【解决方案1】:

要检查的示例 .htaccess 文件:

<IfModule mod_rewrite.c>
  RewriteEngine On

  # Your new base directory for files - example index.html
  RewriteBase /dist/

  # Place for your own rules - example with non-www to www, index.html to domain, http to https

  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteCond %{HTTP_HOST} ![0-9]$ [NC]
  RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301]

  RewriteCond %{REQUEST_URI} ^\/index.(html|htm)$
  RewriteCond %{QUERY_STRING} ^$
  RewriteRule ^(.*)$ https://%{HTTP_HOST}/ [L,R=301]

  RewriteCond %{HTTPS} !=on
  RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]

</IfModule>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-11
    • 2014-11-30
    • 2018-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-29
    相关资源
    最近更新 更多