2013-06-28 18 views
0

最近一直在使用htaccess文件创建重写。对URL和ReWrite规则不起作用的更改

一切运作良好,但已经取得了最近的变化,包括类别名称其次是产品,像这样:

http://localhost/Limestone_Tiles/products/Antalya_Blanc.html 

它只是用来为:

http://localhost/products/Antalya_Blanc.html 

当一切工作好。其中,如下重写规则:

RewriteRule ^products/(.*).html$ product_details.php?&furl=$1 [NC,L] 
RewriteRule ^products/images/(.*)$ images/$1 
RewriteRule ^products/picture_upload/(.*)$ picture_upload/$1 
RewriteRule ^products/thumbnail.php(.*)$ thumbnail.php$1 

因此,为了适应新的变化,我已经改变了重写规则如下:

RewriteRule ^(.*)/products/(.*).html$ product_details.php?&furl=$1 [NC,L] 
RewriteRule ^(.*)/products/images/(.*)$ images/$1 
RewriteRule ^(.*)/products/picture_upload/(.*)$ picture_upload/$1 
RewriteRule ^(.*)/products/thumbnail.php(.*)$ thumbnail.php$1 

现在这种作品,因为

http://localhost/Limestone_Tiles/products/Antalya_Blanc.html 
请问

加载,但没有一个图像 - 当页面没有任何意义时为什么不显示图像?

如果我改变重写规则:

重写规则^ Limestone_Tiles /产品/图片/(.*)$图像/ $ 1

的图像将载入该特定类别!

如果我把图像的URL到浏览器:

http://localhost/Limestone_Tiles/products/images/face.png 

我得到了如下信息:

所请求的网址/图片/ Limestone_Tiles在此服务器上找到。

这也是奇怪的/ images/Limestone_Tiles不是我刚刚粘贴到地址栏的网址。

也许我的重写规则还不正确?

非常感谢您的帮助提前。

回答

1

这是因为您的规则有反向引用第一组分组匹配而不是您真正想要的匹配。说,鉴于这条规则:

RewriteRule ^(.*)/products/(.*).html$ product_details.php?&furl=$1 [NC,L] 

而这个网址:

http://localhost/Limestone_Tiles/products/Antalya_Blanc.html 

重写的URI将是:/product_details.php?&furl=Limestone_Tiles

而在此之前,与旧规则,它会被改写为: /product_details.php?&furl=Antalya_Blanc

如果这是您的预期行为,那很好,除非它违反图像规则:

RewriteRule ^(.*)/products/images/(.*)$ images/$1 

$1反向引用所述第一分组的匹配(.*),所述一个/products/images/之前,而不是实际的图像。它需要更改为:

RewriteRule ^(.*)/products/images/(.*)$ images/$2 

你可能会更好过更改HTML内容,有固定这个形象的东西,而不是创造一个重写规则,以尝试解决它。您可以尝试将其添加到网页的标题中:

<base href="/"> 
+0

太棒了 - 工作很棒!也可以看看你的建议。非常感谢 – mflammia