Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Main Section Web Server
  • Search

Redirect 301 /index.html to / not working

Questions regarding the Web Server
Apache + Nginx, Nginx + PHP5-FPM
Post Reply
  • Print view
Advanced search
10 posts • Page 1 of 1
bannedillo
Posts: 7
Joined: Wed Nov 22, 2017 8:43 am

Redirect 301 /index.html to / not working
  • Quote

Post by bannedillo » Tue Jul 18, 2023 7:59 am

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.
Top

nehavilash
Posts: 12
Joined: Sat Jul 15, 2023 9:33 am
Contact:
Contact nehavilash
Website Facebook Twitter

Os: CentOS 7x
Web: apache + nginx
Re: Redirect 301 /index.html to / not working
  • Quote

Post by nehavilash » Wed Jul 19, 2023 3:11 pm

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.
Top

bannedillo
Posts: 7
Joined: Wed Nov 22, 2017 8:43 am

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

Post by bannedillo » Fri Jul 21, 2023 7:21 am

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
Top

nehavilash
Posts: 12
Joined: Sat Jul 15, 2023 9:33 am
Contact:
Contact nehavilash
Website Facebook Twitter

Os: CentOS 7x
Web: apache + nginx
Re: Redirect 301 /index.html to / not working
  • Quote

Post by nehavilash » Fri Jul 21, 2023 1:06 pm

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
Top

bannedillo
Posts: 7
Joined: Wed Nov 22, 2017 8:43 am

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

Post by bannedillo » Fri Jul 21, 2023 2:25 pm

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
Top

nehavilash
Posts: 12
Joined: Sat Jul 15, 2023 9:33 am
Contact:
Contact nehavilash
Website Facebook Twitter

Os: CentOS 7x
Web: apache + nginx
Re: Redirect 301 /index.html to / not working
  • Quote

Post by nehavilash » 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. 
Top

bannedillo
Posts: 7
Joined: Wed Nov 22, 2017 8:43 am

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

Post by bannedillo » Mon Jul 31, 2023 3:00 pm

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
Top

nehavilash
Posts: 12
Joined: Sat Jul 15, 2023 9:33 am
Contact:
Contact nehavilash
Website Facebook Twitter

Os: CentOS 7x
Web: apache + nginx
Re: Redirect 301 /index.html to / not working
  • Quote

Post by nehavilash » 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.
Top

slipchant
Posts: 8
Joined: Tue Jun 20, 2023 7:52 am

Os: Debian 6x
Web: apache + nginx
Re: Redirect 301 /index.html to / not working
  • Quote

Post by slipchant » Tue Sep 26, 2023 4:31 am

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!
Top

bannedillo
Posts: 7
Joined: Wed Nov 22, 2017 8:43 am

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

Post by bannedillo » Sun Oct 08, 2023 7:58 am

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!
Top


Post Reply
  • Print view

10 posts • Page 1 of 1

Return to “Web Server”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

Login  •  Register

I forgot my password