我想使用htaccess重定向以下示例:
www.site.com/downloads/file1.txt
www.site.com/downloads/folder/file2.txt
到
www.site.com/download?file=file1.txt
www.site.com/download?file=folder/file2.txt
为了示例,请忽略查询字符串中存在斜杠。
答案 0 :(得分:1)
您可以使用mod_rewrite。
RewriteEngine on
RewriteRule "^/downloads/(.+)" "/download?file=$1" [R=301,L]
为重写操作设置正确的HTTP status code(301 - 永久,307 - 临时)。
由于我从未在.htacces中使用过mod_rewrite,因此您可能需要尝试更多组合。也许目录名称需要从正则表达式中删除,因为从.htaccess上下文中已经清楚了 - 手册应该有帮助。
答案 1 :(得分:0)
RewriteEngine on
RewriteRule ^/downloads/(.*) /download?file=$1 [R=301,L]
301 - Moved Permanently
The resource has permanently moved to a different URI.
资源:
HTTP状态代码
http://www.helpwithpcs.com/courses/html/html_http_status_codes.htm#300
Apache mod_rewrite
http://httpd.apache.org/docs/current/mod/mod_rewrite.html