Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过.htaccess重写图像URL_.htaccess_Url_Seo - Fatal编程技术网

通过.htaccess重写图像URL

通过.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

我有这样的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]

如果您的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]