【问题标题】:Image URL Rewrite via .htaccess通过 .htaccess 重写图像 URL
【发布时间】:2016-05-17 06:21:22
【问题描述】:

我有这样的 URL,site.com/img/index.php?id=ID。我想将此重写为 site.com/img/ID/title.jpg

这里是 .htaccess 代码

RewriteEngine On
RewriteBase /img/

RewriteCond %{THE_REQUEST} /index\.php\?id=([^&\s]+) [NC] 
RewriteRule ^ %1/%2? [NC,R,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?id=$1 [QSA,L]

【问题讨论】:

    标签: .htaccess url seo


    【解决方案1】:

    如果您的网址格式类似于此 site.com/index.php?id=ID&title=title.jpg 记住 .jpg 扩展名是固定的,你可以删除它。

    试试这个代码

    RewriteEngine On
    RewriteBase /img/
    RewriteCond %{THE_REQUEST} /index\.php\?id=([^\s]+)&title=([^\s]+)\s [NC]
    RewriteRule ^ %1/%2? [NC,R,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/?/([^/]+).jpg$ index.php?id=$1&title=$2 [QSA,L,NC]
    

    【讨论】:

      猜你喜欢
      • 2019-02-23
      • 1970-01-01
      • 2014-04-07
      • 2015-05-29
      • 1970-01-01
      • 2021-10-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多