我很难将/tumb目录中的.htaccess转换为nginx。
.htaccess文件:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* ../thumb.php [L,QSA]
</IfModule>
我尝试过的:
location /thumb {
rewrite ^(.*)$ /thumb.php;
}
location /thumb {
index thumb.php;
rewrite ^/thumb/(.*)$ /thumb.php;
}
这些不起作用。
编辑:我想我找到了问题,但我仍然对解决方案感到困惑。我制作了一个小的echo-php文件进行测试,所有没有以扩展名结尾的结果似乎都有效。任何以任何扩展名结尾的url都将返回404。
http://www.example.com/thumb工作
http://www.example.com/thumb/jsdlfjfds工作
http://www.example.com/thumb/jsdlfjfds/sfjlkdfjldf工作
http://www.example.com/thumb/asldkjfls.png不工作
http://www.example.com/thumb/zxcvmfds/asldkjfls.jpg不工作
如何重写完整的url,包括/tumb.php的所有扩展名?我一直认为这个正则表达式是指扩展名为^(.*($的完整url?
thumb.php
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
还有另一个位置与文件扩展名匹配,两者似乎不能共存。它们需要放在嵌套的位置。
location /thumb {
location ~* ^.+.(jpg|jpeg|gif|png|bmp|webp|svg|ai|eps)$ {
access_log off;
log_not_found off;
expires max;
rewrite ^(.*)$ /thumb.php;
}
rewrite ^(.*)$ /thumb.php;
}