如何使用htaccess从php渲染某些JavaScript文件 [英] How to make certain javascript files render from php using htaccess

查看:57
本文介绍了如何使用htaccess从php渲染某些JavaScript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我尚未完全确定要在我的.htaccess文件中使用的结构,以实现我想要实现的目标。

So I haven't quite figured out the proper structure to use within my .htaccess file for what I am looking to achieve.

我希望拥有的结构发生的是从文件夹(仅该文件夹)调用的所有javascript文件都是由php文件生成的。我不希望使用.php扩展名或为此创建多个文件。

What I would like to have happen is any javascript files that are called from a folder (and only that folder) are generated by a php file. I'm not looking to have a .php extension or create multiple files for this.

例如

https://www.domain.com/loads/923as0d9f89089asd.js

然后将其发送给类似以下内容的文件:

Would then be sent to something like:

https://www.domain.com/loads/js.php

也不希望在php上使用$ _GET方法。基本上,php文件会检测到文件名,然后从该文件名开始执行该操作。

Not looking to use a $_GET method on the php either. Basically the php file detects the file name and then does what it is supposed to do from there.

在.htaccess文件中进行设置的最佳方法是什么?

What would be the best way to set this up within an .htaccess file?

谢谢!

推荐答案

内部 load / .htaccess 您可以使用以下规则:

Inside loads/.htaccess you can use this rule:

RewriteEngine On
RewriteBase /loads/

RewriteRule ^[\w-]+\.js$ js.php [L,NC]

在您的 js.php 内,您需要使用 $ _ SERVER [ REQUEST_URI] 获取原始JS文件名并提供内容。

Inside your js.php you need to use $_SERVER["REQUEST_URI"] to get original JS filename and serve the content.

这篇关于如何使用htaccess从php渲染某些JavaScript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆