【发布时间】:2014-06-03 07:23:14
【问题描述】:
在我的页面上,我将 silverstripe 框架安装在子文件夹 current 中。我有两个 .htaccessfiles 从 URL 中删除“当前”目录。根之一:
root 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 目录禁止/拒绝访问?
最好的解决方案是外部重定向到同一页面,但 URL 中没有 current。如何在 URL 中没有当前目录的情况下创建到站点的重定向?
所以所有 URL 都会像这样重写(外部):
- domain.com/current --> domain.com
- domain.com/current/example --> domain.com/example
- domain.com/current/what/ever/ --> domain.com/what/ever
到目前为止,我已经找到了这个答案:Url rewrite subfolder to root and forbid accessing subfolder。该解决方案似乎不适用于我的情况。 如果我使用此解决方案访问该页面,则会收到 403 错误和附加错误 500,因为找不到错误文档。
【问题讨论】:
标签: regex apache .htaccess mod-rewrite