首页 文章

更改为URL和重写规则不起作用

提问于
浏览
0

最近一直在使用htaccess文件来创建重写 .

一切都运作良好,但最近做了一个更改,包括产品后面的类别名称,如下所示:

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

会加载,但没有图像可以 - 当页面出现时对我没有意义吗?为什么不是图像?

如果我将重写规则更改为:

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

图像将加载该特定类别!

如果我将图片网址放入浏览器:

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

我得到以下消息:

在此服务器上找不到请求的URL / images / Limestone_Tiles .

这也是奇怪的/ images / Limestone_Tiles不是我刚刚粘贴到地址栏中的Url .

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

非常感谢您的帮助 .

1 回答

  • 1

    这是因为您的规则具有反向引用 the first grouped match 的分组,而不是您真正想要的匹配 . 说,根据这条规则:

    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内容并修复此图像,而不是创建重写规则以尝试更正它 . 您可以尝试将其添加到网页的 Headers 中:

    <base href="/">
    

相关问题