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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With