我刚刚在这个圈子里度过了我生命中的最后10个小时,所以希望有人能够帮助我。
我想要一个特定的URL加载像这样:
http://example.com/f/2011/image.png?attribute=small
当一个这样的格式的URL命中时,我想重写它来击中服务器,如下所示:
http://example.com/generate.php?f=2011/image.png&attribute=small
基于以上,我的问题是双重的:
RewriteEngine On # If it's not an existing file... RewriteCond %{REQUEST_FILENAME} !-f # ...and it's not an existing directory... RewriteCond %{REQUEST_FILENAME} !-d # ...and it starts with "f/" then rewrite it to generate.php RewriteRule ^f/(.*)$ generate.php?f=$1 [L,QSA]
两个RewriteCond
可以省略。 更多信息:
重写规则
QSA的标志
RewriteEngine On RewriteRule ^([az]+)/([0-9]+)/image.png?attribute=small$ generate.php?f=$2/image.png&attribute=small&%{QUERY_STRING} [L]
这是一个有更多机会工作的机会:
RewriteEngine On # If it's not an existing file... RewriteCond %{REQUEST_FILENAME} !-f # ...and it's not an existing directory... RewriteCond %{REQUEST_FILENAME} !-d # ...and it starts with "f/" then rewrite it to generate.php RewriteRule ^([az]+)/([0-9]+)/image\.png$ /generate.php?f=$1 [QSA,L]
请告诉我,如果它的作品