Community

301 Redirect Loop for Wordpress website

Ma
Mansoor #3

This is my complete htaccess code

### Rewrite Rules Added by CyberPanel Rewrite Rule Generator

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.(.*)$
RewriteRule ^(.*)$ http://%1/$1 [L,R=301]

### End CyberPanel Generated Rules.

### Rewrite Rules Added by CyberPanel Rewrite Rule Generator

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

### End CyberPanel Generated Rules.

# BEGIN LSCACHE
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
<IfModule LiteSpeed>
RewriteEngine on
CacheLookup on
RewriteRule .* - [E=Cache-Control:no-autoflush]
RewriteRule \.litespeed_conf\.dat - [F,L]

### marker CACHE RESOURCE start ###
RewriteRule wp-content/.*/[^/]*(responsive|css|js|dynamic|loader|fonts)\.php - [E=cache-control:max-age=3600]
### marker CACHE RESOURCE end ###

### marker LOGIN COOKIE start ###
RewriteRule .? - [E="Cache-Vary:,wp-postpass_49747af18fcec0c3d7d72b73289daec8"]
### marker LOGIN COOKIE end ###

### marker FAVICON start ###
RewriteRule favicon\.ico$ - [E=cache-control:max-age=86400]
### marker FAVICON end ###

### marker DROPQS start ###
CacheKeyModify -qs:fbclid
CacheKeyModify -qs:gclid
CacheKeyModify -qs:utm*
CacheKeyModify -qs:_ga
### marker DROPQS end ###

</IfModule>
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
# END LSCACHE
# BEGIN NON_LSCACHE
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
# END NON_LSCACHE

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

# MalCare WAF
<IfModule LiteSpeed>
  php_value auto_prepend_file '/home/kiltzone.com/public_html/malcare-waf.php'
</IfModule>
<IfModule lsapi_module>
  php_value auto_prepend_file '/home/kiltzone.com/public_html/malcare-waf.php'
</IfModule>
<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 MalCare WAF
jo
josephgodwinke #4

I believe the first two sets of conditions are conflicting each other try this for wordpress

### http to https
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.yoursite.com [NC]
RewriteRule ^(.*)$ https://www.yoursite.com/$1 [L,R=301,NC]
### non-www to www
RewriteRule ^(.*)$ http://yourdsite.com/$1 [L,R=301]
### default wordpress rules
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

If this works now go to your respective plugins and configure them again to set their rules automatically in .htaccess

Ma
Mansoor #5

I tried this and the code is making the site down. After adding the code, I am getting an error “The page isn’t working”

jo
josephgodwinke #6

Try this :

### http to https
RewriteEngine On
RewriteCond %{HTTPS}  !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
### non-www to www
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
### default wordpress rules
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Ma
Mansoor #7

Tried this code and still the same error. Page isn’t working (Too many redirects)

Ma
Mansoor #9

What about that?

Ma
Mansoor #10

What if I don’t use www and http rules at all? And will it automatically redirected if https is enabled and www rule is not added in DNS?

jo
josephgodwinke #11

You can try these rules

### http to https
RewriteEngine On
RewriteCond %{HTTPS}  !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
### default wordpress rules
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

I think the many conditions for a 301 redirect are causing the loop

Ma
Mansoor #12

The code is working but the same error still persist of 301 the sort links are https://kiltzone.com/camouflage-kilts?orderby=rating that are 301 redirecting to https://kiltzone.com/camouflage-kilts/?orderby=rating

The links on these columns and stuffs

jo
josephgodwinke #13

Disable all plugins and enable only that plugin you are using for this feature. See if the issue still persists.

Ma
Mansoor #14

This the default theme feature, not an external plugin

jo
josephgodwinke #15

Then this might be a permalink issue. Can you reset wordpress permalink settings (set to plain) and see if issue persists

Ma
Mansoor #16

I can’t do that as the site is live and getting traffic from SEO so can’t really touch the whole permalink structure.

jo
josephgodwinke #17

You should setup a staging site for this as this is proper way of updating a website in production.

Ma
Mansoor #18

Can you please tell me how to setup a staging site on cyberpanel then?

Sign in to reply