Forum Moderators: phranque
I created a new website that basically runs all from one page. Why? It's a long story ;)
Anyways, I have a .htaccess file that right now runs fine forwarding every request to one page. It looks like this:
RewriteRule (.*) pages\.php?page=$1
Now it works fine for what I have needed but the problem is, I have files and images in specific directories that need to be pulled in the pages and the .htaccess file just goes to pages.php instead of just accessing the file or image.
How can I change that RewriteRule to only work on web pages and not images or other file downloads (ex. pdf, doc, xls, mp3).
Please note, the following will need to forward to pages.php:
/aboutus.html
/products/product.html
/help/contactus.html
The following cannot forward to pages.php:
/images/logo.gif
/files/document.pdf
An easy solution might even be telling the .htaccess file not work on files within the /images/ and /files/ directories.
Can anyone help? :)
Thanks in advance for your help!
Wes
So, with the specific filetypes you mentioned, we can say, rewrite only if NOT those filetypes:
RewriteCond %{REQUEST_URI} !\.(gif¦jpe?g¦png¦css¦js¦doc¦mp3¦pdf¦xls)$
If your site is very busy, put the file extensions in order from most-frequently-requested to least. You want the rule to 'quit' as soon as possible for frequently-requested objects like gif images.
Replace the broken pipe characters "¦" above with solid pipe characters before use; Posting on this forum modifies the pipe characters.
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].
Jim