我们有一个Drupal8站点,在docroot中有一个文件夹。假设它在一个名为micrositefolder的文件夹中。它包含单个index.html文件。
现在假设micrositefolder住在fullsite.com上。我不希望有人通过fullsite.com/micrositefolder访问微型网站,而是只能通过mymicrosite.com访问
我已经通过以下方式实现了这一点:
# Prevent access to the static site from non-static site hosts.
RewriteCond %{REQUEST_URI} ^/micrositefolder [NC]
RewriteCond %{HTTP_HOST} !^mymiscrosite
RewriteRule .* /index.php [L,R=301]
# Only serve the static site if host begins with mymiscrosite.
RewriteCond %{HTTP_HOST} ^mymiscrosite
# Don't loop anything targeting the actual mask directory, to allow
# for linked scripts, stylesheets etc in the static HTML
RewriteCond %{REQUEST_URI} !^/micrositefolder/
#Any requests that made it this far are served from the /micrositefolder/ directory
RewriteRule ^(.*)$ /micrositefolder/$1 [PT]这很好用。我现在可以访问mymicrosite.com,它会为我提供该文件夹中的index.html。
我现在必须在该微型站点上添加另一个页面。url将是mymicrosite.com/ronnie。我在micrositefolder中创建了一个名为ronnie的文件夹,其中包含另一个index.html。
当我试图访问这个网址(mymmicrosite.com/ronnie)时,它被重写成了mymicrosite.com/micrositefolder/ronnie/,但我不知道为什么。我非常确定它与我的代码片段中的最后一行有关,但我不知道如何将其设置为mymicrosite.com/ronnie
需要注意的一件事是,如果我通过mymicrosite.com/ronnie/查看url,它会正常工作,但如果我不在末尾包括斜杠,它会重定向到mymicrosite.com/micrositefolder/ronnie
发布于 2020-07-10 02:43:01
您可以在站点根目录.htacess中的现有规则下添加此规则:
# add a trailing slash to directories
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule [^/]$ %{REQUEST_URI}/ [L]如果当前请求指向一个目录,这将添加一个尾随斜杠。
您提出的方法(在答案中)的问题是:
即使它是无效的URI,它也会执行尾随的斜杠301重定向,例如/micrositefolder/ronnie是实际目录的mymicrosite.com/qwerty111
index.html之前执行额外的
301重定向发布于 2020-07-09 23:56:38
用下面的代码在micrositefolder中添加一个.htaccess似乎解决了我的问题
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]
</IfModule>https://stackoverflow.com/questions/62803916
复制相似问题