Htaccess problem

Some months ago I opened a topic about htaccess redirect: .htaccess redirect

And today, getting back to that project. I set my .htaccess this way:

# Protect HTACCESS
<files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</files>

# Disable HTTP TRACE Method
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]
</IfModule>

# Disable server signature
ServerSignature Off

# Enable X-XSS-Protection Header
<IfModule mod_headers.c>
Header set X-XSS-Protection "1; mode=block"
</IfModule>

# Enable X-Content-Type Header
<IfModule mod_headers.c>
Header set X-Content-Type-Options nosniff
</IfModule>

# Enable Strict Transport Security Header
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
</IfModule>

# Enable X-Frame-Options Header
<IfModule mod_headers.c>
Header set X-Frame-Options "SAMEORIGIN"
</IfModule>

# Disable Directory Listing
Options All -Indexes

# Site where I got the code above: https://www.jinsonvarghese.com/whats-on-my-htaccess/

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

When I am at the home page (https://www.ajudaaqui.ga), it looks like OK, but when I navigate to any article on my website, it returns me the status 404 (https://infinityfree.net/errors/404/).

I’ve already messed with the code so many times, and I am here, completely, stressed with it.

Could you help me, please?

(Some words or sentences may be wrong, because I’m Brazilian and my English is in progress.)

Looking at your website, I guess it uses some kind of Javascript framework to handle page URLs?

If so, you’ll need .htaccess rules to make sure all unknown URLs are routed to the main entrypoint, which is probably the index.html file case.

If your framework has an official example you can use, I would highly recommend using that. But if not, then I just slapped this together which may do the trick (just add this at the end of the existing file):

RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
3 Likes

It works! Thank you!

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