2013-08-01 68 views
1

这似乎超级简单..但我不能为我的生活弄清楚。.htaccess没有按预期运行

我在设计一个页面:index.html。我想将所有流量重定向到index.html。需要注意的是,我在这个页面上有两个图像。 image1.jpgimage2.jpg ......这将最终成为永远不会完成的重定向。于是我想出了以下内容:

# Turn On ReWrite Engine 
RewriteEngine On 

# Exclude image1.jpg and image2.jpg from redirecting 
RewriteCond %{REQUEST_URI} !^/(image1|image2)\.jpg 

# Redirect to index.html 
RewriteRule . index.html [NC,L] 

它的工作原理..也就是说,如果我去:

http://mysite.com/nothing

它的工作原理flawelessly。我想不通的是,如果我去一个目录,图像将不会显示.. IE

http://mysite.com/direcotry/file.whatever

我如何获得图像显示时,网址为“第n “目录数量?

回答

1

这是人们在开始使用所谓漂亮的URL时所面临的常见问题。

解决:解决方案是使用绝对URL为包括图像,CSS和JS文件。确保src属性中的URL始终以正斜杠(/)或http://开头。

+0

斜杠工作完美..谢谢!! – Zak

+0

不客气,很高兴它解决了问题。 – anubhava

0

没有安装mod_rewrite方便运行测试,但这可能是你想要的。

RewriteCond %{REQUEST_URI} !^/([^/]+/)*(image1|image2)\.jpg