Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect script.js to script.php

I have some javascript that is generated by PHP. Currently I am including the javeascript in the html using

<script type="text/javascript" src="js/script.php">

But I want to use

<script type="text/javascript" src="js/script.js">

Now script.js does not exist, but I want it to redirect to script.php without the user knowing.

Can this be done with .htaccess?

like image 205
Jamie Redmond Avatar asked Mar 07 '26 00:03

Jamie Redmond


1 Answers

If your web server supports mod_rewrite, you could do something like this:

RewriteEngine On

RewriteRule ^js/script\.js$ js/script.php

If you have more than one script, you could generalize that RewriteRule by using a backreference from the test pattern:

RewriteRule ^js/(.*)\.js$ js/$1.php
like image 81
Tim Stone Avatar answered Mar 08 '26 19:03

Tim Stone



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!