This is a pretty simple problem, unfortunately I don't understand mod_rewrite syntax so I am unable to solve it. My current .htaccess looks like this: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?route=$1 [L,QSA] Code (markup): Basically, it is just googled solution that rewrites all arguments after index.php. For example: http://www.example.com/index.php?route=blog/index Code (markup): Wil be rewrited to: http://www.example.com/blog/index Code (markup): Now my problem: I need to exclude a folder 'public' from rewriting because all my stylesheets an js scripts are located in that folder and I cannot access them. Please help.
To be more precise: CSS works at pages like: www.example.com Code (markup): www.example.com/blog Code (markup): However it doesn't work when action is specified, e.g.: www.example.com/blog/action Code (markup): will load without CSS styles.
RewriteEngine On RewriteRule ^(.*)/(.*)$ index.php?route=$1/$2 Code (markup): The CSS won't work because of the relative file path you set. If your CSS file is located at www.example.com/style.css, you will have to call it (in the index.php file): <link rel=stylesheet href="/style.css" type="text/css" media=screen> Because at www.example.com/blog/action, if you call the stylesheet with "<link rel=stylesheet href="style.css" type="text/css" media=screen>", it will attempt to find it at http://www.example.com/blog/action/style.css and not http://www.example.com/style.css It doesn't matter that the "real" file, index.php, is located in the correct folder, because with the mod_rewrite rules, the file is now thought to be in a subdirectory, and the relative paths have to be altered accordingly. Sorry, I can't really make myself clear
Hey thanks for help. I have actually solved it by using HTML <base> tag: <base href="<?php echo $baseURL; ?>" /> Code (markup): The $baseURL is defined in PHP as: $baseURL = substr_replace('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'], '', -9, 9).'public/'; PHP: That is the only thing that worked (substr_replace is there to remove the index.php). Is it good solution?
Not really; you're just complicating things. <base href="http://www.example.com" /> would have sufficed. But personally, I'd just used the method I posted above.
I know it would have sufficed. But I'm building a simple PHP framework (just for my own purposes) so I want it to work well on different websites. And I don't want to edit the URL each time I upload the framework on different domain. That's why I went with the simple PHP script mentioned above.
That would be enough most of the time but my version will work also if the whole website is in a subdirectory.