When I write the Sub Page Link To Browser It gives 404 Error

Posted March 17, 2021 381 views

I am hosting a static React page on Digital Ocean. I have sub pages in my site. I can reach the links via navbar but when I copy and paste the link site gives 404 error. For example when I write:
to the browser it gives 404 but I can reach the exact same link when I click to Navbar list item.
And also in localhost it works perfectly fine.

How can I fix it?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi there,

I could suggest using the following .htaccess rules:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteRule . /index.html [L]

Note that you would need to enable AllowOverride in your Apache virtual host:

    <Directory "/var/www/html/">
            Options Indexes FollowSymLinks
            AllowOverride all
            Require all granted

Let me know how it goes!