Css and Js Files Not Found on Production Server

I finally got it. I had the redirect initially on my https config, but the css and js files were not being found. So I took the redirect out and created a configuration for http (port 80) and that worked out fine but only for the http site. I removed the http site and this time I put the redirect on an htaccess file instead, and voila! Everything works now! I still think that I should be able to redirect on the apache config file but at least now I have something that works

Apache configuration is a dark and arcane art - congrats :)

@jacmoe It is indeed a dark place for me! I managed to get the simple test site to show up with css, but not so much luck with the yii framework project. If anyone could take a look at my https configuration and help me get it right it would be greatly appreciated. I have followed the examples on yii framework site but I really don’t know enough about apache configuration. I now have the http redirecting to https site but still no css or js.

Are the files physically present?

Yes. The files are physically present on the server. Some are on the asset folder created by yii and others are on the /css folder and /js folders themselves. They all get a 404 on the browser however. I don’t think its an issue with the actual certificate because I actually get a lock on the page, but I must be missing something on my apache configuration. This is my first time pushing a yii framework project to production. I have worked with zend framework before and I used to add a line on my config file to ignore css and js files from the rewrite condition. I don’t see that in the yii framework examples though so I’m guessing this is not needed.

And the permissions are OK? Viewable by all.

Should be. They work fine on http

The first post of this topic shows how I set my permission

And you did remove the vhost conf for http?

This is my htaccess:





RewriteEngine on


# Redirect http to https

RewriteCond %{SERVER_PORT} ^80$

RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]


# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule . index.php



In ‘web’ directory.

Can’t help you with the actual vhost conf, as I am on Dreamhost where that has been managed for me.

Maybe you should ask on the Web Server section on StackExchange?

There are lots of really hard core Apache geeks there ;)

I am not one of those… :P

Yeah, at these times I wish I WAS one of those! :D My http just has a permanent redirect to my http




<VirtualHost *:80>

	ServerAdmin webmaster@localhost

        ServerName test.example.com

        Redirect permanent / https://test.example.com

</VirtualHost>



This works fine with the test subdomain in which I just have a simple test page with a css file in a css directory. I see my stylesheet there and it applies it perfectly fine to my https:It’s just not working for yii framework. It seems to me like it’s trying to redirect css and js to the index page which would give me a 404 because they are not controller/action/views. What I don’t get is why it only does this on 443 and not on 80.

I noticed just now that I have errors on my own site on local deploy, so if I figure it out, I will post here - if you are not beating me to it. :)

Apache… you are killing me!!! So I added the following line to my https config and now it works.




RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php



Why do I need to add that to my <VirtualHost *443> I have no clue, but it works for some odd reason. And why is this only an issue with 443 Virtual Hosts???

The following 2 lines should already prevent all existing files and directories from following the rewrite rule.




RewriteCond %{"REQUEST_FILENAME} !-f

RewriteCond %{"REQUEST_FILENAME} !-d



@gcarvalho

Congrats!

(I also agree that the Apache config is a kind of dark magic.)

Woo-hoo - I managed to do this myself too :lol:

First some global conf:


Listen 443

SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5

SSLPassPhraseDialog  builtin

SSLSessionCache    	"shmcb:/opt/lampp/logs/ssl_scache(512000)"

SSLSessionCacheTimeout  300



Virtual hosts:


<VirtualHost *:80>

	DocumentRoot "/home/jacmoe/webdev/vhosts/bugitor/frontend/web/"

	ServerName bugitor.dev

	<Directory "/home/jacmoe/webdev/vhosts/bugitor/frontend/web/">

    	AllowOverride All

    	Require all granted

	</Directory>

</VirtualHost>


<VirtualHost bugitor.dev:443> 

	DocumentRoot "/home/jacmoe/webdev/vhosts/bugitor/frontend/web/"

	ServerName bugitor.dev

	<Directory "/home/jacmoe/webdev/vhosts/bugitor/frontend/web/">

    	AllowOverride All 

    	Require all granted

	</Directory> 

	SSLEngine on 

	SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL 

	SSLCertificateFile "/opt/lampp/etc/ssl.crt/bugitor.dev.crt" 

	SSLCertificateKeyFile "/opt/lampp/etc/ssl.key/bugitor.dev.key" 

	SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire


	<FilesMatch "\.(cgi|shtml|pl|asp|php){:content:}quot;> 

    	SSLOptions +StdEnvVars 

	</FilesMatch>


	<Directory /usr/lib/cgi-bin>

                	SSLOptions +StdEnvVars

	</Directory>


	BrowserMatch "MSIE [2-6]" \

                	nokeepalive ssl-unclean-shutdown \

                	downgrade-1.0 force-response-1.0

	BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

</VirtualHost> 



I did not have to do magic for css and js, though…

And I created a self-signed certificate because localhost … ;)

Your magic must be on your htaccess file. I don’t see how you can get yii working without rewrite rules. :)

Not sure if I need this line:


SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire

However, I’ve had more than enough of the edit/restart/curse dance.

At least for now.

Yes, I prefer to keep them in htaccess because I find it easier to tweak/overlook.

Anyway, it is just a standard htacess, which I posted earlier :)

Ah yes! I wonder if moving my rewrite conditions to htaccess would have solved my problem as well. Well, I’m not messing with it now. Maybe for the next project. I will definitely keep that in mind though

Yes, we don’t mess with Apache - at least not more than absolutely necessary, that’s for sure. ;)

i still am stuck here near you somewhere