I've come to a point where I think I'm not allowed to understand how mod_rewrite
works. In theory I think I got it, but just can't seem to make this work. I have the following file structure:
code
-application/
-bundles/
-laravel/
-public/
-css/
-js/
-img/
-index.php
-storage/
-.htaccess
Sadly, my httpd.conf
VHost configuration has this:
<Directory path/to/code>
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
DocumentRoot path/to/code
<IfModule dir_module>
DirectoryIndex index.php
</IfModule>
And I can't modify it to point to code/public/ so I think I could fix it with .htaccess
. Now I've tried everything. Basically what I want to do is convert every request into /public/index.php/($1)
, except css, js, img
which should be converted to:
/public/css/($1)
/public/img/($1)
/public/js/($1)
So if I have example.com/
this will change to example.com/public/index.php
and their css, img, js etc would change to example.com/public/css
, img, js.
I just can't do it :(
My .htaccess
has taken many forms, recently I gave up everything and just look like this:
<IfModule rewrite_module>
RewriteEngine on
RewriteRule ^(.*)$ /public/index.php/$1
</IfModule>
This of course, give me 500 Internal Server Error because it causes loops in the rewriting (is not that clear to me anyways, but still)
So, my idea with .htaccess
was (pseudocode):
<IfModule rewrite_module>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/css
RewriteRule ^css/(.*)$ /public/css/$1
RewriteCond %{REQUEST_URI} ^/img
RewriteRule ^img/(.*)$ /public/img/$1
RewriteCond %{REQUEST_URI} ^/js
RewriteRule ^js/(.*)$ /public/js/$1
RewriteRule ^(.*)$ /public/index.php/$1
</IfModule>
Any idea how can I accomplish this? I would like to understand a little what am I doing wrong. I'll love to figure out how to write good mod_rewrite
.htaccess
files.
I'm on Windows 7, Apache2.2
Thanks in advance.