在我的页面上,我将silverstripe框架安装在一个子文件夹中current
。我有两个.htaccess
文件可从URL中删除“当前”目录。一个根本:
根htaccess:
AddOutputFilterByType deflate text/html text/plain text/css text/javascript application/javascript application/x-javascript application/rss+xml
# Deployment scripts
RewriteCond %{REQUEST_FILENAME} /deploy/
RewriteRule ^(.*)$ $1 [L]
### SILVERSTRIPE START ###
# See: http://www.silverstripe.org/installing-silverstripe/show/12328#post283997
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /current/
RewriteRule ^(.*)$ /current/$1
</IfModule>
### SILVERSTRIPE END ###
AddHandler application/x-httpd-php54 .php
并在该current
文件夹中放置一个:
### SILVERSTRIPE START ###
<Files *.ss>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Files>
<Files web.config>
Order deny,allow
Deny from all
</Files>
ErrorDocument 404 /assets/error-404.html
ErrorDocument 500 /assets/error-500.html
<IfModule mod_alias.c>
RedirectMatch 403 /silverstripe-cache(/|$)
</IfModule>
<IfModule mod_rewrite.c>
SetEnv HTTP_MOD_REWRITE On
RewriteEngine On
RewriteBase '/'
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* framework/main.php?url=%1&%{QUERY_STRING} [L]
</IfModule>
### SILVERSTRIPE END ###
此设置的问题在于,该站点可以作为domain.com和domain.com/current使用。
我如何禁止/拒绝通过current
目录的访问?
最好的解决方案是外部重定向到同一页面,但current
URL中没有。如何在没有URL当前目录的情况下创建到站点的重定向?
因此,所有URL都将被重写(外部),如下所示:
到目前为止,我已经找到了这个答案:Url将子文件夹重写为root并禁止访问该子文件夹。在我的情况下,该解决方案似乎无法正常工作。如果使用此解决方案访问该页面,则会收到403错误和一个附加错误500,因为找不到该错误文档。
我如何禁止/拒绝通过当前目录的访问?
将此规则作为第一个规则插入/current/.htaccess
:
# if direct request is made for /current/abc then external redirect to /abc
RewriteCond %{THE_REQUEST} \s/current/(\S*) [NC]
RewriteRule ^ /%1 [L,R=301,NE]
THE_REQUEST
变量表示Apache从您的浏览器收到的原始请求,在执行某些重写规则后不会被覆盖。/current/
URI请求。本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句