douzhi6160 2019-07-03 20:56
浏览 189
已采纳

特定的wordpress localhost /文件夹被重定向到https:// localhost /文件夹,其他文件夹正常工作

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条回答 默认 最新

  • dongma0722 2019-07-04 07:24
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况