Forum Moderators: phranque
I would like to ask help with setting up Apache configuration (with only .htaccess variables available) that would rewrite internally all non-existing URLs to another one. My target is to create a simple content management script where I could refer to certain pages with a simple url http://mywebserver.com/pagekey.
The script itself is an PHP script and I could, of course, write this out as http://mywebserver.com/myscript.php/pagekey or /myscript.php?page=pagekey and so on. Anyway, for future extensibility and other reasons, I'd like to use a format like /pagekey and give the server to rewrite the URI to a correct physical address.
Anyway, I need to use some files "directly", for example http://mywebserver.com/css/mystyles.css and so on. This kind of requests should be blocked out from rewrite process.
I have been thinking to use 404 error document handler, but it seems like being a bit too unstable and incorrect method.
In addition to all requirements I have told above, I would like to "hide" the physical handler script from the user. All requests should be handled by myscript.php but it should not be visible for the user.
Sounds too complex? Is too complex? ;[smilestopper])
Thanks for comments and tips,
Ville
RewriteCond %{REQUEST_FILENAME} !-f
can be used to execute a following RewriteRule only if the requested resource does not exist as a file.
RewriteCond %{REQUEST_URI} \.css$
could be used to prevent any css files from being rewritten.
If you use the file-exists checking, it should be done only after other exclusions (such as css filetype) are tested. This is because the RewrtieCond for file-exists must check the filesystem to see if the files exists, and that is not a fast operation. So, for example, you'd want to check for the css filetype first.
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com]. The Apache mod_rewrite documentation describes the use of the file-exists checking.
Jim