Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

.htaccess - Apache Rewrite: Simple exception not working for image types

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:

  1. 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.

  2. 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

  3. 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...