I have a .htaccess file on a website I’m working on which rewrites urls from mydomain.com/sub/folder/ to mydomain.com?index.php?controller=sub&view=folder
Unfortunately the way I’ve written it means I can’t access images, stylesheets and other linked files anymore. Could anyone tell me how best to exclude specific directories / URL requests from the rewrite rule?
Apologies if this is a bit of a newbie question, I’m still wrapping my head around this mod rewrite stuff!
The .htaccess file looks like this:
RewriteEngine on
RewriteRule ^([a-zA-Z0-9-]+)/?$ index.php?Controller=$1
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-_]+)/? index.php?Controller=$1&View=$2
If your images are in
mydomain.com/imagesand you are linking to them using relative links on the pagemydomain.com/sub/folder/the browser is going to try to attempt to access the image viamydomain.com/sub/folder/images/i.gif. But if you change your links to absolute links, the browser will correctly attempt to loadmydomain.com/images/i.gif. However, the RewriteRule will change it to:mydomain.com/index/php?Controller=images&View=i.gif. To avoid this you need to add a few RewriteConds:So that when attempting at access an existing file/directory, don’t rewrite to index.php.