htaccess - 静态文件的 RewriteRule
如何将图像和其他静态文件的网址重写到特定文件夹,即我到目前为止正在使用这个:
RewriteRule \.(woff|ttf|svg|js|ico|gif|jpg|png|css|htc|xml|txt)$ /MyFolder/$1
但它不起作用,
请帮忙。
------------------- 更新 ----------------------
好的,现在我有了:
RewriteCond %{HTTP_HOST} ^(www.)?exmpale.com$
RewriteCond %{REQUEST_URI} !^/exmpale.com/
RewriteRule ^(.*\.(woff|ttf|svg|js|ico|gif|jpg|png|css|htc|xml|txt))$ /exmpale.com/$1
RewriteCond %{HTTP_HOST} ^(www.)?exmpale.com$
RewriteRule !\.(woff|ttf|svg|js|ico|gif|jpg|png|css|htc|xml|txt)$ /exmpale.com/index.php
所以图像重定向exmpale 文件夹工作,但现在我想将其他所有内容重写到 index.php,上述解决方案到目前为止不起作用。
干杯, /马尔辛
how to rewrite urls for images and other static files to specific folder, i.e. I am using this so far:
RewriteRule \.(woff|ttf|svg|js|ico|gif|jpg|png|css|htc|xml|txt)$ /MyFolder/$1
but its not working,
please help.
------------------- update ---------------------
ok so now I have:
RewriteCond %{HTTP_HOST} ^(www.)?exmpale.com$
RewriteCond %{REQUEST_URI} !^/exmpale.com/
RewriteRule ^(.*\.(woff|ttf|svg|js|ico|gif|jpg|png|css|htc|xml|txt))$ /exmpale.com/$1
RewriteCond %{HTTP_HOST} ^(www.)?exmpale.com$
RewriteRule !\.(woff|ttf|svg|js|ico|gif|jpg|png|css|htc|xml|txt)$ /exmpale.com/index.php
so images redirected to exmpale folders work but now I would like to rewrite everything else to index.php, above solution is not working so far.
cheers,
/Marcin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许这就是您想要的:
或者也许是这样:
如果这些都不是您想要的,请添加详细信息以及您所需的输入/输出的一些示例。
至于您的更新,您可能希望使用
L
标志在该规则匹配时停止规则处理。例如:Maybe this is what you want:
or perhaps this:
If neither of those is what you're looking for please add details with some examples of your desired inputs/outputs.
As for your update, you probably want to use the
L
flag to stop rule processing when this rule matches. eg:您没有捕获初始请求。尝试以下操作:
这将获取以指定扩展名结尾的任何内容,并在
/MyFolder/
下重定向,例如:/something/image.jpg
现在将转到/MyFolder/something/image.jpg
注意: 通过添加条件来检查文件类型,可能有更好的方法来做到这一点。
You are not capturing the initial request. Try the following:
This will get anything that ends in the extension specified and redirect under
/MyFolder/
For example:/something/image.jpg
will now go to/MyFolder/something/image.jpg
Note: There may be better ways to do this by adding conditions to check for file type.