Forum
Perch Runway and too many redirects issue
Hi,
We have an issue with our .htaccess file for a site we are working on.
The site is new, but has replaced an old site, so as a result we have a large number of redirects set up to stop a decline in traffic from old pages no longer existing.
The problem is we have some rules set up for forcing https, non-www etc, and it works fine when these appear above the 301 redirects, but we want these below all the 301 redirects, at which point we get an error saying too many re-directs.
I've looked at another thread here:
https://forum.grabaperch.com/forum/11-15-2016-too-many-redirects
And tried some of the suggestions, but nothing seems to work. Can anyone help? I know this isn't a direct Perch issue, but does appear to be one encountered more with using Perch Runway than not, so was hoping someone else may have found a solution.
Below I've copied in the template for what we want but doesn't work and causes the error described above (too many redirects - 310 error?)
RewriteEngine On
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
## EXPIRES CACHING ##
#Numerous redirects go here
Redirect 301 /example-1
Redirect 301 /example-2
etc. etc.
# Force https
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Force non-www
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !^/perch
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /perch/core/runway/start.php [L]
I'll leave this here in case anyone wants to help. You might be better with Stack Overflow or somewhere similar though. As you say, it's a general question not specific to Runway.
Hi Drew, thanks for your reply - I've posted it on Stack too, so hopefully someone out there can help!
For anyone else reading this, in case it wasn't clear above, the version of the .htaccess that works is not working for us in terms of the redirects since these can have any variant on the domain (eg. https, http, www., non-www. etc), but when trying to insert the code to rewrite these after the 301 redirects we get the error. As a result, if there's a page such as:
https://www.example.com/my-page
The rewrites will only search for:
https://example.com/my-page
And our seo guy tells us this is having an effect on rankings...
In addition we just tried a different format, keeping the perch rewrite at the top.
This doesn't crash the site straight away like the format above, but certain redirects are instead sent to:
https://example.com/perch/core/runway/start.php
Does this make any sense? This is using the following template in the .htaccess: