Apache Rewrite: Simple exception not working for image types

Deadly 提交于 2019-12-14 03:25:35

问题


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.


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!