gpt4 book ai didi

php - 使用 htaccess 到 php 处理程序页面的 Javascript

转载 作者:行者123 更新时间:2023-11-29 20:08:01 25 4
gpt4 key购买 nike

我的尝试是...

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule \.js$ js.php [L] ## This line is the one I tried to add
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

如果我使用标签 <script type='text/javascript' src='http://www.domain.net/myfile.js'></script>我希望它通过 js.php .

js.php将使用 header('....'); echo file_get_contents('myfile.js'); 处理文件

我已经尝试了很多方法来做到这一点,我以前在一个项目中做过这个,但我不记得现在在哪里,因为我必须重做:)

希望这是有道理的...

最佳答案

您可以添加以下重写规则:

RewriteRule ^([^\.]+)\.js$ js.php [NC,L]

代替:

RewriteRule \.js$ js.php [L]   ## This line is the one I tried to add

结果是:

http://www.domain.net/myfile.js => http://www.domain.net/js.php
http://www.domain.net/foo/bar/myfile.js => http://www.domain.net/js.php

或者你也可以这样做:

RewriteRule ^([^\.]+)\.js$ $1.php [NC,L]

结果是:

http://www.domain.net/myfile.js => http://www.domain.net/myfile.php
http://www.domain.net/foo/bar/myfile.js => http://www.domain.net/foo/bar/myfile.php

关于used RewriteRule flags的一些解释:

  • NC :使用 [NC] 标志会导致以不区分大小写的方式匹配 RewriteRule。也就是说,它不关心字母在匹配的 URI 中是大写还是小写。
  • L : [L] 标志导致 mod_rewrite 停止处理规则集。在大多数情况下,这意味着如果规则匹配,则不会处理进一步的规则。这对应于 Perl 中的最后一个命令,或 C 中的 break 命令。使用此标志指示应立即应用当前规则而不考虑进一步的规则。

关于php - 使用 htaccess 到 php 处理程序页面的 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11295296/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com