Writing a rule in .htaccess to match the correct images folder location

In my single-page-webapp i used the html5 history API so that urls could have a REST pattern (/section1/stuff1..) and i’m planning to make a sort of a javascript router to navigate to several sections of the page depending on the url path.

Right now i’m still working on a local server(wamp) and i added a .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php/$1 [L]

to the app root for that url’s paths containing references to some sections of the page (e.g subdomain/sectionN) can redirect always to the index.php and the redirection was successful BUT all external ressources failed to load and i got :

Resource interpreted as Image but transferred with MIME type text/html: "http://localhost/subdomain/section1/images/imgname.gif".

and it’s logic because the images folder lies in the app root and not under a /section1 folder and the .htaccess rule RewriteRule (.*) index.php/$1 [L] should take only the /images/imgname.gif part and concatinate it after the http://localhost/subdomain/.

I found this as a similar problem so i rewrite the .htaccess file like this :

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?section1/(.+)$ index.php/$1 
RewriteRule (.*) index.php/$1 [L]

but i got a 500 Internal Server Error.


Source: wampserver

Leave a Reply