2

How I can show a JSON file while accessing a URL. I have this JSON file in a folder in my web root. Is it possible to show this JSON file using htaccess rules. My URL is as follows

http://example.com/api/v1/entity

I have api/v1/entity folder structure in my webroot

Can I place this static attributes.json file in the entity folder and on hitting the URL http://example.com/api/v1/entity how can I show the JSON data.

2 Answers 2

5

Place your file inside api/v1/entity/ and name it for example myfile.json.

Create a new file api/v1/entity/.htaccess with this rule:

RewriteEngine On

RewriteRule ^/?$ myfile.json [L]

# return application/json for myfile.json
<Files "myfile.json">
   ForceType application/json
</Files>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the help!
-1

I was having the same issue, the problem was in my .htaccess file I tried to change

 # Deny accessing extensions listed below
<Files ~ "(.json|.lock|.git)">
Order allow, deny
Deny from all
</Files>
SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0

To

# Deny accessing extensions listed below
<Files ~ "(.lock|.git)">
Order allow, deny
Deny from all
</Files>
SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0

Actually removing the .json extension works fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.