我有一系列图像,我想重新命名为SEO目的。 但是,我有超过6000张图像,所以我认为必须轻松重写我的.htaccess文件。
当前图像当前使用以下模式命名:
http://www.mydomain.com/images/small/00005712.jpg
http://www.mydomain.com/images/medium/00005712.jpg
http://www.mydomain.com/images/large/00005712.jpg
我希望能够使用命名方案调用它们,例如:
http://www.mydomain.com/5712s-keyword-phrase.jpg
http://www.mydomain.com/5712m-keyword-phrase.jpg
http://www.mydomain.com/5712l-keyword-phrase.jpg
这将允许我更改显示:
<img src="http://www.mydomain.com/images/large/00005712.jpg" />至
<img src="http://www.mydomain.com/5712l-keyword-phrase.jpg" />重写希望允许我简单地更改我的php文件中的img src属性的模式。 使用新名称在整个站点上的img src属性实际上将原始图像呈现给屏幕。
所有文件名都有8位数字名称,左边是0。
另请注意,如果您知道如何使用左侧的关键字 - 短语和最后的数字来完成此操作,例如http://www.mydomain.com/keyword-phrase-5712s.jpg更好。
如果我没有提供足够的细节,请告诉我我可以做些什么来澄清。 任何有关此事的帮助将不胜感激。
I have a series of images that I would like to rename for SEO purposes. However, I have over 6,000 images so I thought that there must be an easy rewrite for my .htaccess file.
The current images are currently named using the following pattern:
http://www.mydomain.com/images/small/00005712.jpg
http://www.mydomain.com/images/medium/00005712.jpg
http://www.mydomain.com/images/large/00005712.jpg
I would like to be able to call them with a naming scheme such as:
http://www.mydomain.com/5712s-keyword-phrase.jpg
http://www.mydomain.com/5712m-keyword-phrase.jpg
http://www.mydomain.com/5712l-keyword-phrase.jpg
This will allow me to change the display from:
<img src="http://www.mydomain.com/images/large/00005712.jpg" />to
<img src="http://www.mydomain.com/5712l-keyword-phrase.jpg" />The rewrite would hopefully allow me to simply change the pattern on the img src attribute in my php file. The img src attributes across the entire site with the new name would actually present the original images to the screen.
All of the filenames have 8 digit numeric names padded with 0's on the left.
Also note that if you know of a way to do this with the keyword-phrase on the left and the number being at the end, such like http://www.mydomain.com/keyword-phrase-5712s.jpg that it would be even better.
If I've not provided enough details, please let me know what I can do to clarify. Any help on this matter would be greatly appreciated.
最满意答案
如果将文件夹重命名为sm和l,则可以使用1个规则集
RewriteCond %{REQUEST_URI} (.*)\.jpg$ RewriteRule ^0*([1-9])(\d*)(s|m|l)(.*)$ /images/$3/$1$2.jpg否则你需要3
RewriteCond %{REQUEST_URI} (.*)\.jpg$ RewriteRule ^0*([1-9])(\d*)s(.*)$ /images/small/$1$2.jpg RewriteCond %{REQUEST_URI} (.*)\.jpg$ RewriteRule ^0*([1-9])(\d*)m(.*)$ /images/medium/$1$2.jpg RewriteCond %{REQUEST_URI} (.*)\.jpg$ RewriteRule ^0*([1-9])(\d*)l(.*)$ /images/large/$1$2.jpg编辑
根据下面的评论,扔掉文件名前面的SEO术语,使用:
RewriteRule ^.*(\d+)s\.(jpg|gif|png)$ /images/small/$1.$2 RewriteRule ^.*(\d+)m\.(jpg|gif|png)$ /images/medium/$1.$2 RewriteRule ^.*(\d+)l\.(jpg|gif|png)$ /images/large/$1.$2开头的。*会丢弃图像数字前面的任何前导字符。 由于前导零现在包含在文件URL中,我们可以使用(\ d +)匹配(s | m | l)文件夹指示符和图像文件扩展名之前的一个或多个数字。
If you rename your folders to s m and l you can use 1 ruleset
RewriteCond %{REQUEST_URI} (.*)\.jpg$ RewriteRule ^0*([1-9])(\d*)(s|m|l)(.*)$ /images/$3/$1$2.jpgotherwise you need 3
RewriteCond %{REQUEST_URI} (.*)\.jpg$ RewriteRule ^0*([1-9])(\d*)s(.*)$ /images/small/$1$2.jpg RewriteCond %{REQUEST_URI} (.*)\.jpg$ RewriteRule ^0*([1-9])(\d*)m(.*)$ /images/medium/$1$2.jpg RewriteCond %{REQUEST_URI} (.*)\.jpg$ RewriteRule ^0*([1-9])(\d*)l(.*)$ /images/large/$1$2.jpgEdit
per comment below, to throw away SEO terms preceding the file name, use:
RewriteRule ^.*(\d+)s\.(jpg|gif|png)$ /images/small/$1.$2 RewriteRule ^.*(\d+)m\.(jpg|gif|png)$ /images/medium/$1.$2 RewriteRule ^.*(\d+)l\.(jpg|gif|png)$ /images/large/$1.$2the .* at the beginning throws away any leading characters before the image digits. Since the leading zeros are included in the file url now, we can just use (\d+) to match 1 or more digits immediately preceding the (s|m|l) folder indicator and the image file extension.
更多推荐
发布评论