Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSM 5 site setup with a common 404 page redirect

So I am working on a site with 4 sub-domains under the main. They already have an MSM license so I am using that to break out the subs.

My question is:

What is the best way to handle the 404 redirects for all of the sites? I want to use a common 404 page for the main site and all of the sub-domains.

On the main site, it is easy enough.

{if no_results OR segment_3!=""}
    {redirect="404"}
{/if}

But wouldn't the other sites just register a page view for things like analytics if I were to just add:

{if no_results OR segment_3!=""}
    {embed="default_site:_includes/404"}
{/if}

I would like to be able to have the same results site wide and catch all 404 stats.

Thanks, Brian

like image 613
W3bGuy Avatar asked Oct 31 '12 21:10

W3bGuy


1 Answers

Ok, So what I ended up with was the following:

I created a template group of "_includes" in each site. I then created a template "404-Page" in each of those sites' template groups. (This was really just for ease for remembering. They could be in whatever template group, template config you want)

Each one of these contained the following:

{embed="default_site:_includes/404-Page"}

Then under each site, under: Design => Templates => Global Preferences

I set the site to "Enable Strict URL's" = 'Yes' and "404 Page" = "_includes/404-Page"

I checked this in the header sent and it triggers the 404 fine. One of the issues I ran into was this running on a Windows server under IIS7. I also had to disable the 404 Errors in the web.config file and process a custom 404 code like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpErrors errorMode="Custom" existingResponse="Replace">
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" path="/index.php/_includes/404-Page.html" responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>
</configuration>

I placed this web.config file in each of the site's root folders. Being the paths were named the same, this was a simple paste/dump.

I hope this helps someone else out. ;)

like image 151
W3bGuy Avatar answered Nov 18 '22 19:11

W3bGuy