首页 文章

.htaccess重写规则,以防止图像url重写

提问于
浏览
0

我对htaccess重写规则很新 . 我需要将url myurl.com/1000/samsung-123 重写为 myurl.com/user/product.php?id=1000 . 我在 .htaccess 文件中使用了以下重写规则 .

RewriteEngine on
RewriteBase /

RewriteRule ([0-9]+)/(.*)$ user/product.php?id=$1 [PT,L]

规则运作正常 . 然而,它也重写了我的图像网址 myurl.com/img/_product/1000/1000A.jpg .

我怎么能阻止这个呢?如果在网址中输入了扩展名(如 .jpg.png.php ),是否有办法跳过规则?

2 回答

  • 0

    您可以使用以下内容跳过静态文件 . 这不仅可以使用图像,还可以使用样式表,脚本等 .

    RewriteEngine on
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]
    
    RewriteRule ([0-9]+)/(.*)$ user/product.php?id=$1 [PT,L]
    
  • 0
    RewriteEngine on
    RewriteBase /
    
    RewriteCond img/_product/$1/$1A.jpg !-f
    RewriteRule ([0-9]+)/(.*)$ user/product.php?id=$1 [PT,L]
    

    也许这会有所帮助 .

    • 已修复 .

相关问题