Does ReactJS give 403 error?

My website without ReactJs was working fine, but I decided to update it and let it more professional (I guess), and it gives me the 403 error.

Can’t I use ReactJs?

403 means forbidden, which means either you have decided to use directory protection or something is wrong with the current configuration. JS libraries are very unlikely to cause an 403 error.

Ok, so how do I host my react website? Could you help me?

React runs fully within a web browser, so we couldn’t block it if we tried. So whatever is causing the 403 error, I’m not so certain that your use of the React framework is the issue.

Can you please share a URL where you see this 403 error so we can check it for ourselves?

2 Likes

I guess I’m hosting it wrongly or I need to create a backend.

https://www.ajudaaqui.ga is the URL.

Edit: I remind something that its name is deploy, I have to do it, right?

I made deploy and it works!

Now, the problem is I can’t access this page: https://www.ajudaaqui.ga/artigos/ganhar-dinheiro-online-2021/

That’s probably caused by an issue with your .htaccess rules/

From your Javascript code, you can push a visible URL to the browser address bar to show, which works if your Javascript application is already loaded.

But if you navigate directly to the URL, the server needs to know where to route that URL, which can be done with .htaccess rules.

Does React.js come with a default .htaccess file which you could use?

3 Likes

I guess no.

But I use this code on my .htaccess:

<files ~ “^.*.([Hh][Tt][Aa])”>
order allow,deny
deny from all
satisfy all

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Options -Indexes

Options +FollowSymLinks -MultiViews RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC] RewriteRule ^ %1 [R,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.html -f RewriteRule ^(.*?)/?$ $1.html [L]

I’m trying to access my page on https://www.ajudaaqui.ga/artigos/ganhar-dinheiro-online-2021 but it returns 404 error.

I’m using ReactJs to develop it and this is my .htaccess:

<files ~ “^.*.([Hh][Tt][Aa])”>
order allow,deny
deny from all
satisfy all

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Options -Indexes

Options +FollowSymLinks -MultiViews RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} [1]{3,}\s([^.]+).html [NC] RewriteRule ^ %1 [R,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.html -f RewriteRule ^(.*?)/?$ $1.html [L]


  1. A-Z ↩︎

In the htaccess, where it says Options -MultiViews change it Options +MultiViews, this will allow you to visit pages without having file extensions (eg mysite.com/myfile instead of mysite.com/myfile.php

3 Likes

I merged your topics, please don’t create multiple topics about your React .htaccess rules.

Your .htaccess rules look a bit odd to me. The block at the end does some URL rewriting based on the request URL. But I would expect some explicit reference to the index.html file, since that file is the central entrypoint/controller for your web pages.

A quick web search pointed me to this .htaccess example, which looks a lot more likely to work to me:

2 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.