Silverstripe mod_rewrite issue (I think) - .htaccess

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.

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.

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

Related

htaccess RewriteRule leaving the current directory scope

I'm creating a website based on wordpress on a hosting system (unfortunately not a dedicated system in this situation) and I am very limited in my configuration opportunities for Apache2.4.x / PHP8.
I was unable to convince my client to move to a more advanced environment, so I have to work with the given playground, as follows:
There is a website in /www/ which is linked to the domain (A-Record). There's an old man that maintains the current website until the new website is finished.
I am really not afraid that the old dev accesseses my development scope intentionally or uses PHP to do so to cause harm (he doesn't know PHP, he uploads locally generated HTML). He's an old man and I'm rather afraid that he accidently deletes, overwrites or moves my work while I'm working on the new website and I have to put it back together. He might be like "oh I don't know that folder" and it's gone.
My first task was to make and install certificates and enforce HTTPS, that worked pretty well so far.
Now I need www.domain.tld/dev/ to show the wordpress site, however the old developer can access the www scope and I really don't want him to mess with my code. He barely knows HTML.
In opposite to him, I have full access and can go outside of the /www/ directory, so I created a /wordpress/. Unfortunately I have no option to add a subdomain for that on said host, either.
Now here's where my problem and my approaches kick in, I am unable to move /www/dev/ to show the /wordpress/ content which is not inside of /www/.
Theoretically I would do this on my root server but my client wants the website development to happen in his webspace. That's a bit strange but no subject to change. Just take that as given fact please.
So my htaccess rules for this are not doing anything and I can not spot what's wrong.
(Note: The .htaccess is laying inside of /www/)
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^domain.tld [NC]
RewriteRule ^(.*)$ https://domain.tld%{REQUEST_URI} [R=301,L]
#RewriteBase /
#RewriteRule ^/dev /is/htdocs/wpCUSTOMERIDSTRIPPED/wordpress [QSA]
#RewriteRule ^/dev/(.*) /is/htdocs/wpCUSTOMERIDSTRIPPED/wordpress/$1 [QSA]
RewriteBase /is/htdocs/wpCUSTOMERIDSTRIPPED
RewriteRule ^/www/dev /wordpress [QSA]
RewriteRule ^/www/dev/(.*) /wordpress/$1 [QSA]
Thank you alot in advance.
Note: The search function did not help me further as I am moving outside of the scope of the active directory.

How do i change the .htaccess on cPanel's Online File Manager (ByetHost)?

I'm using ByetHost as my website's FTP service, i configure everything (besides uploading the stuff) via ByetHost's Vista Panel, which has a Online File Manager where i presume i could edit the .htaccess.
However when i arrive at the File Manager, i can't seem to find the .htaccess file, and there is also a lack of a Settings button too.
Here is what the File Manager looks like: (the htdocs is where all my website's stuff is at)
I know ByetHost and/or whatever this unknown File Manager is not well known, but i'd like to ask anyways if there's anyone that could help me on how to configure my .htaccess. I would appreciate it.
I had this issue too, and couldn't find any settings or otherwise.
So what I simply did was:
Just created a new file and named it .htaccess!
And a quick test, I put in the following to allow access to my .html pages without actually typing the extension:
RewriteEngine on
RewriteRule ^(.+)\.html$ /$1 [R,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*?)/?$ /$1.html [NC,END]
And it worked successfully.

Redirect all accessible URL's to only one specific subdomain

I have my working worpress domains, subdomain and alias working normally and locate at root web server "www/".
htpps://domain.com
htpps://domain.net
htpps://en.domain.net
Later I decide to install a support web application in same server in folder "www/support/".
Setting this support app I needed to set one domain or subdomain, and I set "support.domain.com".
After last step I realise that all the following URL's could access to the support app:
htpps://domain.com/support
htpps://domain.net/support
htpps://en.domain.net/support
htpps://support.domain.com/support
htpps://support.domain.net/support
Since this support app doesn't work correctly with differents domains or subdomains from the main one that was set initially ( that was: "support.domain.com" ), I'm trying to redirect all to one unique subdomain: "support.domain.com".
The file ".htaccess" locate in support app folder ("www/support/.htaccess") still empty, all rewrite rules I try didn't worked, due my low knowledge.
How could I redirect all accessible URL's to only one "support.domain.com"?
or
Block all access to this folder "www/support/index.php" that are not "support.domain.com"?
I found and try lots of similar questions but none work correctly or give too many redirections.
in support.htaccess, you can use the following rule
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.+ http://support.domain.com/ [L]
After several time pass over, I finally locate the problem, double quotes was “ instead of "
This small details was creating problem in every .htaccess file in my host, after this correction all working correctly and it reach support/.htaccess now.

Can't get my Zend Framework 2 project working on hosting server

Currently I am developing a webshop in PHP. For this I use the Zend Framework 2.
All of my routes exist of a locale i.e. "nl_NL" or "en_EN", followed by a controller and an action www.mydomain.com/nl_NL/profile/login. Look here for an example of a route used in my project. This one belongs to the Profile Module: http://pastebin.com/jmim47w8.
If the visitor has no account, and no Cookie is set, the locale variable will first be set to the variable retrieved from the following function:
locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE'])
If a cookie is set that value will be used.
On the other hand, if a user does have an account and is logged in, the variable used will be retrieved from the user's profile.
My entire script does work on a localhost. However, on the server it doesn't.
When loading the page nothing gets shown. I have checked the error logs and couldn't find anything. However, when i place /nl_NL/ or any other locale that meets the requirements of the "locale route" regex in the url manually, it does work.
My first thought was that the url_rewrite apache module was not installed or activated, but since other websites use this module as well, and they are on the same server this doesn't seem logical. Of course I did try to check wether it was enabled by running some scripts, but to no avail. Since our server is setup to not allow shell scripts to be ran, or to check wether apache modules are enabled using phpinfo() it's quite hard to make sure.
I have tried to verify that my .htaccess file is correct, but I'm pretty much a noob at .htaccess. This is my .htaccess:
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
To see what my IndexController looks like look here: http://pastebin.com/AEgm3Jmk.
All in all, I would really like to know how to get a Zend FW 2 project to work on a hosting server while still using url rewrite or any other way that makes it possible to use locale variables.
If there is something missing from this post that is needed to help me further, I will be happy to post it.
I have solved the problem, everything is working fine right now.
I found the problem to be in my local.php config file. The problem was
an error within this file, so it was actually a write error ( corrupt file ).
#Alex thanks for the help though, appreciate it.

net::ERR_INCOMPLETE_CHUNKED_ENCODING

I use .htaccess to rewrite url from someurl.com/ to someurl.com/public/. First .htaccess in www root contains this:
DirectoryIndex ./public/
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ ./public/$1 [QSA]
and second one in folder /public/ contains this:
DirectoryIndex _main.php
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ ./?params=$1 [QSA]
And the problem is when I open url someurl.com/ without "public". Page is loaded correctly, but in Google Chrome console I got error: net::ERR_INCOMPLETE_CHUNKED_ENCODING. When I open url someurl.com/public/ page loads without any error.
Any ideas, please?
In my case, the problem was cache-related and was happening when doing a CORS request.
I post my response here cause this is the first resource I found on Google for net::ERR_INCOMPLETE_CHUNKED_ENCODING error.
Forcing the response header Cache-Control to no-cache resolved my issue:
[ using Symfony HttpFoundation component ]
<?php
$response->headers->add(array(
'Cache-Control' => 'no-cache'
));
I had this issue when trying to access some parts of the WP admin area, I managed to resolve it by adding the below to my functions.php file;
add_filter('wp_headers', 'wpse167128_nocache');
function wpse167128_nocache($headers){
unset($headers['Cache-Control']);
return $headers;
}
We had net::ERR_INCOMPLETE_CHUNKED_ENCODING problem in case of HTML, which contained too much empty lines. Some browsers had difficulties with interpretation of long files.
Once we made applied code cleaning in our templates by cleaning code from empty lines, all was perfect.
I was also facing same issue. Finally i got this was the permission issue on cache folder.
I decided changing the file : /etc/apache2/mods-enabled/cgid.conf
Adding the following code snippet:
<IfModule mod_cgid.c>
CGIDScriptTimeout 60
</IfModule>
This problem is really general, in my case I deactivated the WP Super Cache plugin, and didn't get the bug anymore, but this is so general that no one can really help you because of different configurations of servers/wordpress
In my case, the problem was the Windows anti-virus software (Kaspersky). Turning it off, the problem was gone :/
For me it was the Zend PHP Opcache. It had reached its memory limit and could no longer cache all scripts. This was a problem for a massive code base like Magento 2.
Increasing the memory limit solved the issue after weeks of banging head on desk.
It is about server side problem.
The user has running web service does not right access to web server cache folder.
Make sure nginx user can write to /var/lib/nginx (or /var/cache/nginx in some distros).
Make sure nginx user can write to the folder (find the nginx user form nginx configuration file is located usually in /etc/nginx/nginx.conf)
Give the right access (chown -R nginx:nginx /var/lib/nginx/)
Reload the service(-service nginx reload -in centos)

Resources