在 SilverStripe 的子文件夹中安装另一个 PHP 应用程序时出错



我在 www.mywebsite.com 上安装了Silverstripe(我只是作为一个例子编造的)

我正在 www.mywebsite.com/test 上测试Wordpress

这是我根文件夹中的 .htaccess 文件:

### SILVERSTRIPE START ###
# Deny access to templates (but allow from localhost)
< Files *.ss >
Order deny,allow<br>
Deny from all<br>
Allow from 127.0.0.1
< /Files >
# Deny access to IIS configuration
< Files web.config >
Order deny,allow
Deny from all
< /Files >
# Deny access to YAML configuration files which might include sensitive information
< Files ~ ".ya?ml$">
Order allow,deny
Deny from all
< /Files>
# Route errors to static pages automatically generated by SilverStripe
ErrorDocument 404 /assets/error-404.html
ErrorDocument 500 /assets/error-500.html
< IfModule mod_env.c>
# Ensure that X-Forwarded-Host is only allowed to determine the request
# hostname for servers ips defined by SS_TRUSTED_PROXY_IPS in your _ss_environment.php
# Note that in a future release this setting will be always on.
SetEnv BlockUntrustedIPs true
< /IfModule>
 < IfModule mod_rewrite.c>
 # Turn off index.php handling requests to the homepage fixes issue in apache >=2.4
  < IfModule mod_dir.c>
    DirectoryIndex disabled
  < /IfModule>
  SetEnv HTTP_MOD_REWRITE On
 RewriteEngine Off
  # Enable HTTP Basic authentication workaround for PHP running in CGI mode
 RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Deny access to potentially sensitive files and folders
RewriteRule ^vendor(/|$) - [F,L,NC]
RewriteRule silverstripe-cache(/|$) - [F,L,NC]
RewriteRule composer.(json|lock) - [F,L,NC]
# Process through SilverStripe if no file with the requested name exists.
# Pass through the original path as a query parameter, and retain the existing parameters.
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* framework/main.php?url=%1 [QSA]
# If framework isn't in a subdirectory, rewrite to installer
RewriteCond %{REQUEST_URI} ^(.*)/framework/main.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . %1/install.php? [R,L]
< /IfModule><br>
### SILVERSTRIPE END ###
 < IfModule pagespeed_module>
ModPagespeed Off
</IfModule>
 < IfModule mod_expires.c><br>
  ExpiresActive Off<br>
< /IfModule>

代码/test/.htaccess:

< IfModule mod_rewrite.c><br>
SetEnv HTTP_MOD_REWRITE On<br>
RewriteEngine On<br>
RewriteBase /<br>
RewriteCond %{REQUEST_URI} !/test<br>
RewriteEngine On<br>
RewriteCond %{REQUEST_FILENAME} !-f<br>
RewriteCond %{REQUEST_FILENAME} !-d<br>
RewriteRule . /index.php [L]<br>
< /IfModule> 

有什么想法吗? 注意:
不会显示在实际文件中,并且<和>之间没有空格

我得到了我所有文件的列表。 我的索引.php文件甚至没有正确显示,URL 从/test 更改为 test/?url=/test

我使用 zoom.ph 共享主机。

更新:

根 .htacccess 文件中的新代码:

RewriteEngine On
# Change any direct URLs (www.unclebubby.com...) to the subdomain   (wavs.unclebubby.com)
RewriteCond %{HTTP_HOST} ^(www.)?collegeconnect.ph$ [NC] 
RewriteCond %{REQUEST_URI} ^/test/(.*)$ [NC] 
RewriteRule .* http://test.collegeconnect.ph/%1 [R=301,L]
RewriteCond %{REQUEST_URI} !/test
 # If there is a .htm at the end of the URL, get rid of it (due to migration of site from FrontPage)
RewriteCond %{REQUEST_URI} ^/(.+).htm$ [NC] 
RewriteRule ^.+.htm$ /%1 [R=301,L]
RewriteBase /
### SILVERSTRIPE START ###

我对此进行了测试,您拥有的似乎工作正常。只要确保你的htaccess没有错误。你可以检查apache.log为此。

这是我使用的:

DirectoryIndex index.html index.php
<IfModule mod_rewrite.c>
SetEnv HTTP_MOD_REWRITE On
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/test
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

这成功地将我重定向到Wordpress设置页面(全新安装)。

首先,你在test/.htaccess中的RewriteBase是错误的。它不是"/"(根),而是"/test/"(因为文件在那里)。

其次,你在test/.htaccess中有两次"RewriteEngine On" - 这可能不是错误,但无论如何都不需要。

第三 - 您的 test/.htaccess 文件实际上被行禁用:

RewriteCond %{REQUEST_URI} !/test

这意味着 - 所有在 URL 中没有"test"的请求,任何对"test"文件夹的请求都无法完成。你的test/.htaccess应该看起来像这样:

< IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /test/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
< /IfModule> 

奖励:Silverstripe扫描安装它的整个文件夹,并将这些类添加到其清单中,这意味着您应该通过在中放置名为"_manifest_exclude"的空文件来排除wordpress(即文件夹"test"

)。

在"RewriteBase"中提及文件夹名称,如下所示在根路径的.htaccess文件中

RewriteBase '/SilverStripe/'

其中 SilverStripe 是您的文件夹名称,如您提到的

RewriteBase '/test/'

请记住在文件夹名称前后添加斜杠。如果它不起作用,那么请告诉我。谢谢

相关内容

最新更新