我有一个名为/manuals的目录,其中包含多个PDF文件。
我想要实现的是重定向并向访问此目录的任何URL附加一个pdf扩展名,如下所示:
https://website.com/manuals/FM0100 to https://website.com/manuals/FM0100.pdf这在.htaccess文件中是可能的吗?
发布于 2020-08-12 16:31:53
经过实验,我找到了一个解决方案:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} manuals
RewriteCond %{REQUEST_URI} !pdf
RewriteCond %{REQUEST_URI} !png
RewriteCond %{REQUEST_URI} !jpg
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}.pdf
</IfModule>发布于 2020-08-12 17:13:38
在/manuals/.htaccess文件中(即在/manuals子目录中),您可以这样做:
RewriteEngine On
# Append ".pdf" to any request that does not already have a file extension.
RewriteRule !\.\w{2,4}$ %{REQUEST_URI}.pdf [R=302,L]该请求通过302 -临时重定向从外部重定向。
或者,您可以在内部重写请求(即。通过删除R=302标志对用户隐藏的.pdf扩展)。
<IfModule>包装器不是必需的。
https://stackoverflow.com/questions/63372499
复制相似问题