skip to Main Content

I have a webspace directory structure similar to the following

  • website

    • api

    • public_html

      • assets

The problem is that I need to access the files in the api folder from an AJAX call within a JavaScript file within public_html. I was thinking I could use Apache rewrite rules to accomplish this. The AJAX call would use the following url, for example, "api/example.php" and with the use of the rewrite engine, hopefully, that would get rewritten to access the file in the api folder outside the website root.

I don’t have much experience with the Apache rewrite engine at all, so I wouldn’t have even the slightest of ideas, if possible, on how to accomplish this.

Would appreciate any help at all, thanks.

2

Answers


  1. I think you can achieve it with the help of subdomain, create subdomain from cpanel and set api as root directory then you can access api folder in ypur ajax call with the help of subdomain. Hope this will help for you.

    Login or Signup to reply.
  2. Instead of rewriting the urls, you should configure apache to also service the API directory. This can be done via an alias. Here is an example:

    Alias /api/ "/var/www/website/api"
    <Directory "/var/www/website/api/">
    </Directory>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search