‘Access to restricted URI denied’ and BASE href in MooTools

Whilst performing a standard Request.HTML with MooTools 1.2 I suddenly encountered an unexpected ‘Access to restricted URI denied’ error even though the .PHP page I was referencing was in the same directory as the file which was referencing it.

var sendform = new Request.HTML({
url:'ajax-email.php',
update: $('email-response')
}).post($('contact'));

The reason

The problem was triggered by an inconsistent use of the ‘www’ subdomain. The site behaved as expected until I added a static <base> href to the header which included the ‘www’ prefix.

When the page was subsequently accessed without the www prefix the ‘Access to restricted URI denied’ was triggered as the AJAX request from MooTools evidently took the <base> href into consideration and thus resulted in a domain mismatch.

Solution one

Use $_SERVER[‘HTTP_HOST’] in the <base> href to reinforce consitency.

Solution two

Use a .htaccess file to redirect all traffic from www.domain.com to domain.com or visa versa and thus clear up the ambiguity.