问题
This question seems simple to me though I can't seem to get it to work.
I'm trying to do a simple rewrite for all requests except defined image types.
Three very important clarifications:
This is being done with the .htaccess file in the image directory that accessed from a browser is located at example.com/images/ so the .htaccess file is located at public_html/images/.htaccess locally.
This solution needs to play nicely with the awesome help I received from other people at this question: Apache Rewrite: image directory based on HTTP host
I'm using shared hosting, not VPS or dedicated so my access is limited; I know this isn't going to be complicated anyway.
I've tried the following (along with modifications of it) without success:
public_html/images/.htaccess
RewriteEngine on
RewriteRule !\.(gif|jpg|png)$ index.php?q=$1 [L]
I think I'm probably just missing something simple here.
回答1:
I presume you are trying redirect everything to index.php
when the request to images
folder is not a request to an image file.
Try this:
RewriteEngine on
RewriteCond %{REQUEST_URI} !\.(gif|jpg|png)$ [NC]
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
来源:https://stackoverflow.com/questions/9162845/apache-rewrite-simple-exception-not-working-for-image-types