.htaccess 表示 PDF URL
我有一个名为 /pdf/
的结构,其中存储生成的 PDF。我正在尝试使用 .htaccess 将访问者路由到 PDF 文件夹。
我的 .htaccess 文件中有此规则:
RewriteEngine On
RewriteBase /
RewriteRule (.*) index.php?page=$1.html
RewriteRule ??? for pdf??
(注意 ???
标记...)
当我尝试访问网址 /manual_chap_1
它正在工作。但是当我尝试 /pdf/manual_chap_1
时,它似乎不起作用。这是我看到的一些输出:
$_GET[page] => index.php.html
我希望能够生成 PDF 文件,如果请求的位置不存在 PDF 文件,然后,我希望它加载 HTML 页面。
I have a structure called /pdf/
where generated PDFs are stored. I am trying to use .htaccess to route visitors to the PDF folder.
I have this rule in my .htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule (.*) index.php?page=$1.html
RewriteRule ??? for pdf??
(Note the ???
marks...)
When I try to access the url /manual_chap_1
it is working. But when I try /pdf/manual_chap_1
it doesn't seem to be working. Here is some output I see:
$_GET[page] => index.php.html
I want to be able to generate the PDF file, if the PDF file does not exist in the requested location, and then, I want it to load an HTML page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
L: [L] 标志导致 mod_rewrite 停止处理规则集。在大多数情况下,这意味着如果规则匹配,则不会处理更多规则。这对应于 Perl 中的最后一个命令,或 C 中的 break 命令。使用此标志指示应立即应用当前规则,而不考虑进一步的规则。
QSA:当替换 URI 包含查询字符串时,RewriteRule 的默认行为是丢弃现有查询字符串,并将其替换为新生成的查询字符串。使用 [QSA] 标志会导致查询字符串被组合。
NC:使用[NC]标志会导致RewriteRule以不区分大小写的方式进行匹配。也就是说,它不关心匹配的 URI 中字母是大写还是小写。
此外,我建议使用破折号而不是下划线。
Try this:
L: The [L] flag causes mod_rewrite to stop processing the rule set. In most contexts, this means that if the rule matches, no further rules will be processed. This corresponds to the last command in Perl, or the break command in C. Use this flag to indicate that the current rule should be applied immediately without considering further rules.
QSA : When the replacement URI contains a query string, the default behavior of RewriteRule is to discard the existing query string, and replace it with the newly generated one. Using the [QSA] flag causes the query strings to be combined.
NC: Use of the [NC] flag causes the RewriteRule to be matched in a case-insensitive manner. That is, it doesn't care whether letters appear as upper-case or lower-case in the matched URI.
Also, I would recommend to use dashes instead of underscore.