通过.htaccess重写图像URL
我有这样的URL,site.com/img/index.php?id=id。我想将其重写为site.com/img/id/title.jpg 这是.htaccess代码通过.htaccess重写图像URL,.htaccess,url,seo,.htaccess,Url,Seo,我有这样的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
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]
如果您的Url格式类似于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]