admin管理员组文章数量:1430672
So I haven't quite figured out the proper structure to use within my .htaccess file for what I am looking to achieve.
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.
An example is
.js
Would then be sent to something like:
.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.
What would be the best way to set this up within an .htaccess file?
Thanks!
So I haven't quite figured out the proper structure to use within my .htaccess file for what I am looking to achieve.
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.
An example is
https://www.domain./loads/923as0d9f89089asd.js
Would then be sent to something like:
https://www.domain./loads/js.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.
What would be the best way to set this up within an .htaccess file?
Thanks!
Share Improve this question asked Aug 14, 2016 at 17:26 MrTechieMrTechie 1,8476 gold badges21 silver badges36 bronze badges 3- redirect them to a different php file and serve them from there – Akshay Khandelwal Commented Aug 14, 2016 at 17:31
- Have you already looked at the htaccess concepts of Rewrite and Redirects? – KumarM Commented Aug 14, 2016 at 17:32
- This might help you: htaccesscheatsheet./#rewrite-and-redirection. I has a lot of examples. – KumarM Commented Aug 14, 2016 at 17:36
2 Answers
Reset to default 5Inside loads/.htaccess
you can use this rule:
RewriteEngine On
RewriteBase /loads/
RewriteRule ^[\w-]+\.js$ js.php [L,NC]
Inside your js.php
you need to use $_SERVER["REQUEST_URI"]
to get original JS filename and serve the content.
You could have something like this (untested, may need modification) :
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/loads/(.*).js$
RewriteRule ^/loads/(.*).js$ http://www.domain./loads/js.php?file=$1 [P]
And your js.php script will be called internally, it will receive the JS filename from GET but it's not visible by the user.
This will use mod_proxy with the [P] flag.
More informations here : https://httpd.apache/docs/current/rewrite/flags.html#flag_p
本文标签: How to make certain javascript files render from php using htaccessStack Overflow
版权声明:本文标题:How to make certain javascript files render from php using htaccess - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745548249a2662807.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论