Page 1 of 1

Redirect 301 /index.html to / not working

Posted: Tue Jul 18, 2023 7:59 am
by bannedillo
Hi All,

I have Vesta installed with Nginx + Apache2.

I have this .htaccess set up:

Code: Select all

# Disable MutliViews
Options -Multiviews

ErrorDocument 404 /index.html

RewriteEngine on

# Remove www subdomain and redirect to HTTPS
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Remove "index.html" from all URLs
RewriteRule ^(|.+/)index\.html$ /$1 [R=301,L]
if I put: www.domain.com, redirects perfectly to domain.com

the problem comes with the index.html, if I put domain.com/index.html or www.domain.com/index.html will not redirect to domain.com.

If I remove all this code, will not work any redirection even the first one: www.domain.com to domain.com.

thank you in advance.

Re: Redirect 301 /index.html to / not working

Posted: Wed Jul 19, 2023 3:11 pm
by nehavilash
First of all, you can't use both Nginx + Apache2 web servers at the same time. 
Nginx does not provide native htaccess support. 

It looks like there might be a problem with how Apache is set up or how the.htaccess file is being read. 
Re-setup the Apache configuration. 

Code: Select all

<Directory /path/to/your/YourSiteDirectory>
    AllowOverride All
    Require all granted
</Directory>
note: The.htaccess File Location should be in the root/public directory and is being read by Apache.

The Rewrite Module Should be enabled.

Code: Select all

sudo a2enmod rewrite
sudo systemctl restart apache2
Now You can briefly change the.htaccess file to make it easier to find the problem. Try out the reroute with the following simple.htaccess file:

Code: Select all

RewriteEngine On
Redirect 301 /index.html /
Save it and test if it works for you...
You can verify your URL on this tool, https://redirectchecker.com/ to get its detailed redirection path and its HTTP status code. give you some general idea of how your URL is being redirected. 
note: above code is just for testing and giving a general idea; that's it.

Re: Redirect 301 /index.html to / not working

Posted: Fri Jul 21, 2023 7:21 am
by bannedillo
Thank you for your help.

I did everything as you said, but it seemed everything was already good in that way.

I tried later to use:

Code: Select all

RewriteEngine On
Redirect 301 /index.html /
But no luck, when I enter to domain.com/index.html ... stays in domain.com/index.htm there is no redirection to domain.com

and when I enter to domain.com it gives Error

thanks again

Re: Redirect 301 /index.html to / not working

Posted: Fri Jul 21, 2023 1:06 pm
by nehavilash
Let's try a different approach..

Code: Select all


Options -Multiviews

ErrorDocument 404 /index.html

RewriteEngine On

# Remove www subdomain and redirect to HTTPS
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# Redirect /index.html to root /
RewriteRule ^index\.html$ / [R=301,L]

# Redirect HTTP to HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
restart apache2

let me know if you have still issue

Re: Redirect 301 /index.html to / not working

Posted: Fri Jul 21, 2023 2:25 pm
by bannedillo
thank you again.

I did the change on the .htaccess and restarted apache2 through the Vesta panel.

for: www.domain.com, does 301 to domain.com

with redirectchecker, does 301 and then 200.

when entering: domain.com/index.html only shows code 200, no redirection to domain.com, keeps the domain.com/index.html

thanks

Re: Redirect 301 /index.html to / not working

Posted: Wed Jul 26, 2023 9:18 pm
by nehavilash
Let's try a another method to see if it resolves the problem..
backup of your current .htaccess then try change it

Code: Select all

Options -Multiviews

ErrorDocument 404 /index.html

RewriteEngine On

# Redirect /index.html to root /
RewriteRule ^index\.html$ / [R=301,L]

# Remove www subdomain and redirect to HTTPS
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# Redirect HTTP to HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
please restart Apache again

Once done, Verify manually to see if redirection is working, and also check on redirect checker to make sure it's working properly as you expected. 

Re: Redirect 301 /index.html to / not working

Posted: Mon Jul 31, 2023 3:00 pm
by bannedillo
nehavilash wrote:
Wed Jul 26, 2023 9:18 pm
Let's try a another method to see if it resolves the problem..
backup of your current .htaccess then try change it

Code: Select all

Options -Multiviews

ErrorDocument 404 /index.html

RewriteEngine On

# Redirect /index.html to root /
RewriteRule ^index\.html$ / [R=301,L]

# Remove www subdomain and redirect to HTTPS
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# Redirect HTTP to HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
please restart Apache again

Once done, Verify manually to see if redirection is working, and also check on redirect checker to make sure it's working properly as you expected. 

Thank you for your help.

I don't know, but still not working properly, when adding /index.html, no redirection is working... very strange.

thanks again

Re: Redirect 301 /index.html to / not working

Posted: Wed Aug 09, 2023 1:06 pm
by nehavilash
Instead of having multiple redirection rules, try setting a single rule for handling index.html
let me see what happen this time.

Code: Select all

RewriteEngine On
RewriteRule ^index\.html$ / [R=301,L]

# Redirect www subdomain to non-www and HTTP to HTTPS
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R=301,L]
I hope it will work.

Re: Redirect 301 /index.html to / not working

Posted: Tue Sep 26, 2023 4:31 am
by slipchant
nehavilash wrote:
Wed Aug 09, 2023 1:06 pm
Instead of having multiple redirection rules, try setting a single rule for handling index.html breakout game
let me see what happen this time.

Code: Select all

RewriteEngine On
RewriteRule ^index\.html$ / [R=301,L]

# Redirect www subdomain to non-www and HTTP to HTTPS
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R=301,L]
I hope it will work.
It's worked when adding /index.html Many thanks!

Re: Redirect 301 /index.html to / not working

Posted: Sun Oct 08, 2023 7:58 am
by bannedillo
nehavilash wrote:
Wed Aug 09, 2023 1:06 pm
Instead of having multiple redirection rules, try setting a single rule for handling index.html
let me see what happen this time.

Code: Select all

RewriteEngine On
RewriteRule ^index\.html$ / [R=301,L]

# Redirect www subdomain to non-www and HTTP to HTTPS
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R=301,L]
I hope it will work.
Thank you, still having the problem, and now I have tested different option.

I have changed the file extension of my index.html website to index.php, then on the .htaccess I've put this one:

Code: Select all

RewriteEngine On
RewriteRule ^index\.php$ / [R=301,L]

# Redirect www subdomain to non-www and HTTP to HTTPS
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://domain.com/$1 [R=301,L]

Now, If I put domain.com/index.php redirects to: domain.com

why with .php is working and not with .html?

many thanks!