Apache mod_rewrite和正则表达式

在我的HTML中我想引用我的图像:</ p>

  <代码> /images/articles/this-is-the-page-title-dgj4klci5j4.jpg
/images/gallery/ 这是-page-title-qj3k56l6kfm.jpg
</ code> </ pre>

但它们的确位于:</ p>

  / _ pics / articles / dgj4klci5j4.jpg 
/ _pics / articles / thumbs / dgj4klci5j4.jpg
/ _pics / gallery / qj3k56l6kfm.jpg
</ code> </ pre>

我的。 htaccess文件当前位于站点的根目录中,如下所示:</ p>

  RewriteEngine On 

RewriteCond%{HTTP_HOST} ^ website \ .com [NC] \ nRewriteRule ^(。*)$ http://www.website.com/$1 [R = permanent,L]

RewriteRule ^ articles / user / articles.php [L]
RewriteRule ^ gallery / info / gallery.php [L]
</ code> </ pre>

我必须这样做,因为在最后可能的时刻,客户决定他想要更清晰的图像文件名,这似乎是一个快速合理的f ix。</ p>

我想我可以将所有内容从/ images重定向到/ _pics并通过使用mod_rewrite取出页面标题。 问题是我对正则表达式不是很好,我不完全理解mod_rewrite的工作方式。 我可以得到一些帮助吗? 谢谢</ p>

真实图像文件名只包含字母和数字,可以是jpg或png。</ p>
</ div>



In my HTML I want to refer to my images like this:


but they are really located at:


My .htaccess file is currently in the root directory of the site and looks something like this:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^website\.com [NC]
RewriteRule ^(.*)$ http://www.website.com/$1 [R=permanent,L]

RewriteRule ^articles/ user/articles.php [L]
RewriteRule ^gallery/ info/gallery.php [L]

I have to do this because in the last possible moment the client decided that he wants more legible image filenames and this seems like a quick reasonable fix.

I imagine that I could redirect everything from /images to /_pics and take the page title out by just using mod_rewrite. Problem is that I'm not very good with regular expressions and I don't fully understand the way mod_rewrite works. Can I get some help? Thanks

The real image filename only contains letters and numbers and can be jpg or png.


尝试在htaccess文件中添加此规则:</ p>

  RewriteRule ^ images /(  。+)/ [^ /] +  - ([^ /  - ] +)\。(jpe?g | gif | png)$ /_pics/$1/$2.$3 [L] 
</ code> </ pre >
</ div>



Try adding this rule in the htaccess file:

RewriteRule ^images/(.+)/[^/]+-([^/-]+)\.(jpe?g|gif|png)$ /_pics/$1/$2.$3 [L]

dou29106 谢谢,工作就像一个魅力
大约 8 年之前 回复
Csdn user default icon