htaccess URL重写 - 在倒数第二个和最后一个连字符后获取参数

时间:2013-09-08 14:00:47

标签: .htaccess url-rewriting

我需要使用.htaccess URL重写从URL中获取var1和var2。

URL:

<a href="tmp/image-file-name-var1-var2.jpg">link</a>

htaccess的:

RewriteEngine On
RewriteRule ^tmp/([^\.]+)(here i need help)\.(png|jpg|gif)$    image.php?image=$1.$4&size=$2&position=$3 [NC,L]

结果应该是:

image.php?image=image-file-name.jpg&size=var1&position=var2

1 个答案:

答案 0 :(得分:1)

您可以使用此代码:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^tmp/(.+)-([^-]+)-([^.]+)\.(png|jpe?g|gif)$ index.php?image=$1.$4&size=$2&position=$3 [L,QSA,NC]