1

I got a freelance job of migrating a website to a new server. They only provided me with the backup files, which should be enough. While I can just upload it to the server and try to run it directly from there, I want to test it locally, because this is my standard workflow. But when I try to access "localhost/folder", it redirects to "https://localhost/folder".

It is a PHP site using a Wordpress framework which I'm not familiar with. It only happens with this specific site and on Chrome, Firefox and Edge. I'm using WAMP as my php server on Windows 10.

I tried creating different new folders with index files, they worked normally, tried to replace the project's index file for a working one, tried renaming the folder, but no success.

I tried this question: Wordpress localhost not working

which was marked as a duplicate of this question: Google Chrome redirecting localhost to https

None of them helped either.

EDIT: Content of the .htaccess file

#Options +FollowSymlinks
#Header add X-Frame-Options "DENY"
#Header add X-XSS-Protection "1; mode=block"
#Header add X-Content-Type-Options "nosniff"
#Header unset link
#Header unset Server
#Header unset X-Pingback
#ServerSignature Off
# HTTPS forced by SG-Optimizer
<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteCond %{HTTPS} off
   RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
</IfModule>
# END HTTPS
# BEGIN WordPress
<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /
   RewriteRule ^index\.php$ - [L]
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule . /index.php [L]
</IfModule>
# END WordPress
<IfModule mod_expires.c>
   ExpiresActive On
   # Images
   ExpiresByType image/jpeg "access plus 1 year"
   ExpiresByType image/gif "access plus 1 year"
   ExpiresByType image/png "access plus 1 year"
   ExpiresByType image/webp "access plus 1 year"
   ExpiresByType image/svg+xml "access plus 1 year"
   ExpiresByType image/x-icon "access plus 1 year"
   # Video
   ExpiresByType video/mp4 "access plus 1 year"
   ExpiresByType video/mpeg "access plus 1 year"
   # CSS, JavaScript
   ExpiresByType text/css "access plus 1 month"
   ExpiresByType text/javascript "access plus 1 month"
   ExpiresByType application/javascript "access plus 1 month"
   # Others
   ExpiresByType application/pdf "access plus 1 month"
   ExpiresByType application/x-shockwave-flash "access plus 1 month"
</IfModule>
<IfModule mod_deflate.c>
   SetOutputFilter DEFLATE
   <IfModule mod_setenvif.c>
      <IfModule mod_headers.c>
         SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
         RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
      </IfModule>
   </IfModule>
   <IfModule mod_filter.c>
      AddOutputFilterByType DEFLATE "application/atom+xml" \
      "application/javascript" \
      "application/json" \
      "application/ld+json" \
      "application/manifest+json" \
      "application/rdf+xml" \
      "application/rss+xml" \
      "application/schema+json" \
      "application/vnd.geo+json" \
      "application/vnd.ms-fontobject" \
      "application/x-font-ttf" \
      "application/x-font-opentype" \
      "application/x-font-truetype" \
      "application/x-javascript" \
      "application/x-web-app-manifest+json" \
      "application/xhtml+xml" \
      "application/xml" \
      "font/eot" \
      "font/opentype" \
      "font/otf" \
      "image/bmp" \
      "image/svg+xml" \
      "image/vnd.microsoft.icon" \
      "image/x-icon" \
      "text/cache-manifest" \
      "text/css" \
      "text/html" \
      "text/javascript" \
      "text/plain" \
      "text/vcard" \
      "text/vnd.rim.location.xloc" \
      "text/vtt" \
      "text/x-component" \
      "text/x-cross-domain-policy" \
      "text/xml"
   </IfModule>
   <IfModule mod_mime.c>
      AddEncoding gzip              svgz
   </IfModule>
</IfModule>
# Wordfence WAF
<Files ".user.ini">
   <IfModule mod_authz_core.c>
      Require all denied
   </IfModule>
   <IfModule !mod_authz_core.c>
      Order deny,allow
      Deny from all
   </IfModule>
</Files>
# END Wordfence WAF
# START XML RPC BLOCKING
<Files xmlrpc.php>
   Order Deny,Allow
   Deny from all
</Files>
# FINISH XML RPC BLOCKING
<files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</files>
<files wp-config.php>
   order allow,deny
   deny from all
</files>
# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php7_module>
   php_flag display_errors Off
   php_value max_execution_time 30
   php_value max_input_time 30
   php_value max_input_vars 1000
   php_value memory_limit 128M
   php_value post_max_size 10M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php72"
   php_value upload_max_filesize 10M
   php_flag zlib.output_compression On
</IfModule>
# END cPanel-generated php ini directives, do not edit

There´s also another htaccess file callde .htaccess3, not sure if it does anything or is just a backup:

# php -- BEGIN cPanel-generated handler, do not edit
# NOTE this account's php is controlled via FPM and the vhost, this is a place holder.
# Do not edit. This next line is to support the cPanel php wrapper (php_cli).
# AddType application/x-httpd-ea-php72 .php .phtml
# php -- END cPanel-generated handler, do not edit

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

# END WordPress

# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php7_module>
   php_flag display_errors Off
   php_value max_execution_time 30
   php_value max_input_time 30
   php_value max_input_vars 1000
   php_value memory_limit 128M
   php_value post_max_size 10M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php72"
   php_value upload_max_filesize 10M
   php_flag zlib.output_compression On
</IfModule>
# END cPanel-generated php ini directives, do not edit

1 Answers1

0

Sounds to me like the site tries to force HTTPS via the .htaccess file in the root directory. Check that file - in case you can't see it, it's a hidden file, so enable those in your explorer.

Look for a line like this:

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]

Delete it, and it should fix your problem. If it doesn't, update your answer with the full content of the .htaccess file, so we can have a look.

Andrew
  • 827
  • 2
  • 6
  • 14
  • Found those lines, but the RewriteCond is set to off. Delete it didn't do anything. – José Elias Fernandes Jul 04 '19 at 21:32
  • Hm, that whole section was supposed to be it, beginning with "# HTTPS forced by SG-Optimizer" until "# END HTTP". It means if HTTPS is off (same as !=on in my example), it should redirect the request to HTTPS. Maybe after deleting those lines, try emptying wordpress cache, and restart apache? If it still tries to redirect you after that, then i'm at a loss. – Andrew Jul 05 '19 at 06:17