Silverstripe mod_rewrite issue (I think)

我的梦境 提交于 2019-12-24 04:44:12

问题


A site I've been working on, which has been working fine on my local dev and live dev environments is giving me issues when I try to deploy it to a live server (the client wants to host it with their existing hosting provider).

I uploaded the site to the server and updated the database config as I have done many times before on both my and other's servers without issue. This time, however, I was presented with:

SilverStripe Framework requires a $databaseConfig defined.

When I removed the .htaccess file from the root folder, the site appeared, however, all the URLs appeared like so:

www.domain.com/index.php/page_name

After a few searches, I came across a solution to the index.php issue; to add the following to my _config file

Director::setBaseURL('/');

I did this and the URL's appeared correctly, however navigating to them would give me a 404.

I reinstated the htaccess file and narrowed it down to this block:

RewriteCond %{REQUEST_URI} ^(.*)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !\.php$
    RewriteRule .* framework/main.php?url=%1 [QSA]

When this is in place, I get the database config error mentioned above, when it's not there, my urls produce 404s

Does anyone have any insight as to what can be going on here? I've had a lot of back and forth with the host and he's not very knowledgable and can't offer any advice and I'm no genius when it comes to this side of things.


回答1:


I'll assume you are using SilverStripe 3.1+ so the Director config could/should be placed in your YAML config file (the static will be deprecated):

Director:
  alternate_base_url: '/'

Although this helps mainly on issues with base_tag.

The main ModRewrite issue might however be solved by adding a RewriteBase:

RewriteEngine On
RewriteBase '/'

You can use '/' or the folder SS is installed in if not the public root. This is usually automatically handled by the SilverStripe installer by checking $base = dirname($_SERVER['SCRIPT_NAME']); and other little things. Check install.php5 line 1483, you might be able to use this to figure out your RewriteBase.

If that doesn't work, try a fresh install instead of copying to the server your local install.




回答2:


Do you use a _ss_enviroment.php to define your database config details? I had a similar experience like from in a project i migrated from SS 2.4 to 3.1.2.

Set this in your site _config.php

// Use _ss_environment.php file for configuration
//Please note that your system should have a file, _ss_environment.php, with database connectivity data,
require_once("conf/ConfigureFromEnv.php");

global $database;
$database = '';

I hope this helps



来源:https://stackoverflow.com/questions/20475176/silverstripe-mod-rewrite-issue-i-think

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!