Apache Rewrite:仅重写索引 URL,无论深度如何,但文件扩展名例外
尽管理解设置很重要,但我已经有点工作了。
通过多域支持(多个域使用完全相同的软件副本),我只需要重写目录(像 dir1/ 或 dir2/ 一样干净地结束)。
从视觉上看,这里是引用文件的位置...
site1.com/gallery/image.jpg
site2.net/gallery/image.png
gallery/ (此处为 PHP 代码)
.htaccess
所以我只想将目录重写为 gallery/,而所有图像文件(按扩展名)都重写为 site1/gallery/image.jpg 路径。
我目前所拥有的仅重写基本图库/路径,但它不会重写更深的图库索引(例如 gallery/my_gallery/),但图像异常也能正常工作。
RewriteEngine on
RewriteRule ^[^/]*/gallery/$ gallery/$1 [QSA]
RewriteCond %{REQUEST_URI} !\.(gif|jpg|png)$
RewriteCond %{REQUEST_URI} !.*/(gallery|admin|blog)
RewriteRule !\.(css|js)$ index.php
那么如何在保持图像文件异常的同时捕获所有目录(无论深度如何)?
I have this somewhat working though it's important to understand the setup.
With multi-domain support (multiple domains using the exact same copy of software) I need to rewrite ONLY the directories (which end cleanly like dir1/ or dir2/).
Visually here are where the files are referenced...
site1.com/gallery/image.jpg
site2.net/gallery/image.png
gallery/ (PHP code here)
.htaccess
So I want to have only directories rewritten to gallery/ while all image files (by extension) are rewritten to the site1/gallery/image.jpg paths.
What I have currently rewrites ONLY the base gallery/ path however it does NOT rewrite deeper gallery indexes (e.g. gallery/my_gallery/) however the image exception does work as well.
RewriteEngine on
RewriteRule ^[^/]*/gallery/$ gallery/$1 [QSA]
RewriteCond %{REQUEST_URI} !\.(gif|jpg|png)$
RewriteCond %{REQUEST_URI} !.*/(gallery|admin|blog)
RewriteRule !\.(css|js)$ index.php
So how to I capture all directories regardless of depth while maintaining the image file exception please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,我所需要做的就是将文件扩展名添加到重写条件中。另外,值得注意的是,重写条件必须出现在重写规则之前。
Turns out all I needed to do was add the file extensions to the rewrite condition. Also it's VERY important to note that the rewrite condition must appear before the rewrite rule.