Apache Rewrite:简单异常不适用于图像类型

发布于 2025-01-03 02:44:25 字数 729 浏览 1 评论 0原文

这个问题对我来说似乎很简单,但我似乎无法让它发挥作用。

我正在尝试对除定义的图像类型之外的所有请求进行简单的重写。

三个非常重要的说明:

  1. 这是通过从浏览器访问的图像目录中的 .htaccess 文件来完成的,该文件位于 example.com/images/,因此 .htaccess 文件位于public_html/images/.htaccess 本地

  2. 这个解决方案需要与我从其他人那里收到的关于这个问题的出色帮助很好地配合:Apache Rewrite:基于 HTTP 主机的图像目录

  3. 我使用的是共享主机,而不是 VPS 或专用主机,因此我的访问受到限制;我知道这不会很复杂。

我已经尝试了以下操作(及其修改)但没有成功:

public_html/images/.htaccess

RewriteEngine on
RewriteRule !\.(gif|jpg|png)$ index.php?q=$1 [L]

我想我可能只是在这里错过了一些简单的东西。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听风念你 2025-01-10 02:44:25

当对 images 文件夹的请求不是对图像文件的请求时,我假设您正在尝试将所有内容重定向到 index.php

试试这个:

RewriteEngine on
RewriteCond %{REQUEST_URI} !\.(gif|jpg|png)$ [NC]
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

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]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文