图像URL通过.htaccess重写

时间:2016-05-17 06:21:23

标签: .htaccess url seo

我有这样的网址,site / 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]

1 个答案:

答案 0 :(得分:1)

如果你的网址格式是这样的网站http://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]