croxton / Stash

Stash allows you to stash text and snippets of code for reuse throughout your templates.
GNU General Public License v3.0
197 stars 20 forks source link

404 redirection #163

Closed anyamiretsky closed 5 years ago

anyamiretsky commented 5 years ago

Hi Mark, This isn't really an issue, more of a question. How do I make the .htacess Static Page Caching rules work to redirect to our custom 404 page when a nonexisting URL is entered? Ours redirects only to our home page.

croxton commented 5 years ago

All requests for pages are passed on to EE to handle, so make sure you set the the 404 page in EE: https://docs.expressionengine.com/latest/urls/404pages.html

If you your hosting environment is running PHP as a CGI, FastCGI or PHP-FPM then make sure to add a ? to the rule that rewrites to index.php, to force query strings:

https://github.com/croxton/Stash/wiki/Static-caching-homepage-in-FastCGI-environments

croxton commented 5 years ago

Also see: https://github.com/croxton/Stash/wiki/%7Bexp%3Astash%3Anot_found%7D

anyamiretsky commented 5 years ago

Thanks for responding Mark. How do I know how PHP is running? I do see CGI/1.1 as the Gateway_Interface in phpinfo? Do I also need to add the new rules described in https://github.com/croxton/Stash/wiki/Static-caching-homepage-in-FastCGI-environments as well the ? to the index.php rewrite? I'm fairly new to EE and web development, so I apologize in advance for these questions.

anyamiretsky commented 5 years ago

Someone else just told me to turn on 'enable strict URLs' in EE and that has fixed the issue. Will this interfere with static caching though?

croxton commented 5 years ago

Ah yes, you do need to turn that on for 404s to work. No it won't interfere with static caching.

One important thing - don't static cache the 404 page itself. Some guidelines here which really apply to all sites that use static caching (not just EE): https://github.com/croxton/Stash/wiki/Caching

The extra block of rewrite rules is only needed if you want to static cache the homepage: https://github.com/croxton/Stash/wiki/Static-caching-homepage-in-FastCGI-environments

anyamiretsky commented 5 years ago

Hi Mark, Looks like my solution above won't work for me. We have templates that we view directly in our first segment without a template group and this setting will not allow this to happen. So there must be some other way around this since this since our 404's used to work at some point. I found an interesting schematic at:

(http://www.jamessmith.co.uk/images/ExpressionEngine_url_schematic.png)

There is something there which might explain what is happening, but I'm not sure what the option 'is a visible template in default template group' means (second column, fifth one down)? Any ideas?