【问题标题】:URL rewrite to Subfolder (root redirection to subdirectory) .htaccessURL 重写到子文件夹(根重定向到子目录).htaccess
【发布时间】:2020-01-08 03:57:53
【问题描述】:

使用以下规则处理来自/page 子目录的请求,并重写 URL:

<IfModule mod_rewrite.c>
   RewriteEngine On

   RewriteCond %{HTTP_HOST} ^fastload.website$ [NC]
   RewriteRule ^(.*)$ https://www.fastload.website/$1 [L,NC,QSA,R=302]

   RewriteCond %{DOCUMENT_ROOT}/page/$1.html -f
   RewriteRule ^(.*)$ page/$1.html [L,NC]
</IfModule>

这将从fastload.website/page/test.html 提供fastload.website/test 但是,无法使用斜杠fastload.website/test/

【问题讨论】:

    标签: apache .htaccess redirect url-rewriting subdirectory


    【解决方案1】:

    您可以从 RewriteRule 匹配中排除斜线。

    RewriteCond %{DOCUMENT_ROOT}/page/$1.html -f
    RewriteRule ^(.*?)/?$ page/$1.html [L,NC]
    

    【讨论】:

      猜你喜欢
      • 2017-01-29
      • 2021-09-03
      • 2011-01-19
      • 2011-01-14
      • 1970-01-01
      • 2011-02-03
      • 2012-02-27
      • 1970-01-01
      相关资源
      最近更新 更多