Simple mod_rewrite rules broken after new version c9

I am working on a project hosted in Cloud9 IDE . I had a simple mod_rewrite ruleset, but they no longer work after deploying a new c9 version. It took me forever to iron out those rules (I'm a beginner at best). I'm confused as to why these rules don't work anymore (AFAIK, newer version c9 shouldn't affect mod_rewrite rules).

Here are the rules (located in the root directory .htaccess

)

RewriteEngine on
Options FollowSymLinks

RewriteBase /

RewriteCond %{REQUEST_URI} ^/css/.*$ [OR]
RewriteCond %{REQUEST_URI} ^/img/.*$ [OR]
RewriteCond %{REQUEST_URI} ^/js/.*$
RewriteCond Astralis/resources%{REQUEST_URI} -f
RewriteRule ^(.+)$ Astralis/resources/$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

      

The goal is pretty simple ... All requests sent to /css/...

/img/...

or /js/...

should serve the associated file internally Astralis/resources

(after checking if the file exists). Otherwise, redirect the rest of the traffic to index.php.

The problem I am experiencing is that all resource requests (css, img, js) return 404. If I move the / css, / img and / js folders from astralia / resources back to the root directory, all resources are loaded as expected way. This issue came after a new version of c9 with no changes to the .htaccess file, codebase or directory structure.

Any clue as to what's going on? How should I debug this stuff? Any general advice / guidance for writing mod_rewrite rules would also be appreciated. Thank.

+3


source to share


1 answer


Since Apache needs the full path to the file in order to return true with -f

, you will need to use %{DOCUMENT_ROOT}/

before your file path.

Have it like this:



RewriteEngine on
Options FollowSymLinks

RewriteBase /

RewriteCond %{REQUEST_URI} ^/(css|img|js)/ [NC]
RewriteCond %{DOCUMENT_ROOT}/Astralis/resources%{REQUEST_URI} -f
RewriteRule ^(.+)$ Astralis/resources/$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

      

+2


source







All Articles