skip to Main Content

The old site had a (302) redirect from / to /index.shtml.

The new site will be visible on / instead.
For SEO reasons we want a 301 redirect from /index.shtml to /.

However if I add that redirecting the htaccess file we get stuck in an infinite loop. So somewhere there still has to be a redirect from / to index.shtml, but where?

The old site was installed in the root directory /.
The new site is still in /dev/ (not my choice), however htaccess makes sure when someone goes to / they actually see the site in /dev/. The htaccess is saved in / and not /dev/.

Where could the old redirect from /index.shtml to / be?

My line of code in htaccess that creates a problem:

Redirect 301 /index.shtml http://www.example.com/

Could the error be caused by:

IfModule mod_rewrite.c (with brackets)

RewriteEngine On

RewriteBase /

RewriteRule ^index.php$ – [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

/IfModule (with brackets)

2

Answers


  1. Your Redirect is causing the infinite loop .as it redirects /index.shtml to your document root which already points to /index.shtml .

    To fix this or to set the **/index.shtml** as your root directory handler ,you can use one of the following methods :

    DirectoryIndex

    DirectoryIndex index.shtml

    DirectoryIndex will internally forword your **/** home directory to **/index.shtml** .

    Mod-rewrite :

    RewriteEngine ^$ /index.shtml [L]

    This will rewrite your home directory to **/index.shtml** .

    if you want to redirect /index.shtml to / , you can use the following rule :

    RewriteEngine on
    RewriteCond %{THE_REQUEST} /index.shtmls
    RewriteRule ^index.shtml$ / [L,R]
    

    This will redirect /index.shtml to / without causing the infinite loop.

    Login or Signup to reply.
  2. I know I’m coming late to the party, but the issue is the browser not the site. 301 and 302 redirects are both cached by recent browsers so you’ll experience loops when you change them to point back to something that previously redirected.

    You can test it with incognito mode and you’ll see the redirect loop won’t happen for you anymore. This is because incognito mode doesn’t cache or observe the cache for redirects outside of its own session.

    Unfortunately, there’s no way to ensure that previous visitors don’t get stuck in the loop which is why you should be very careful using 301 redirects. 302 redirects, as “temporary” redirects, will behave better with redirection loops, but the better solution would have been to use DirectoryIndex to load index.shtml as the default document instead of redirecting to it (which is what ultimately caused your problem).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search