I checked this post here Making a plugin file accessible via url rewrite? which seems to have the same problem as me but its for a plugin. But so far i am getting 404.
add_action( 'init', 'my_rewrite' );
function my_rewrite() {
global $wp_rewrite;
add_rewrite_rule('/$', '/wp-content/themes/econ/adserver/adserver.js.php', 'top');
$wp_rewrite->flush_rules(true);
}
I have this file path /wp-content/themes/econ/adserver/adserver.js.php
and need to show it as http://mysite.com/adserver.js.php
UPDATE:
The code that Bainternet gave is working good except the rewrite rule part. I can now access the file using index.php?myjs=true
. Here is the code in my htaccess file you might wanna take a look.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
/$
is bad news, change to something likejs/$
and your url tomysite.com/js/adserver.js.php
/adserver$
to have something likemysite.com/adserver/adserver.js.php
but did not worked either.<script>
can be completely encapsulated by a PHPfunction some_script() {}
call, allowing you to pass PHP variables to the script.