We have pages on our site that aren’t part of the CMS, and we’d like to leave them separate. But when you try to access them, ModX routes you to the default error page, based on either "OnPageNotFound" or "OnPageUnauthorized".
I tried writing a plugin to deal with this, and have gotten most of the way. But I’m not sure how to allow access to the page once I tap into the system event. Both "sendRedirect" and "sendForward" don’t seem to be the right methods (see line "DO SOMETHING HERE" below).
Is there an easier way to allow a passthrough for certain pages? We have SEO names turned on, if it matters.
Thanks for any tips,
John
// ------------------
$e = &$modx->Event;
switch ($e->name)
{
case "OnPageNotFound":
if(!$pg)
{
$target_url = $_SERVER["REQUEST_URI"];
if ($target_url == "/stats")
{
// DO SOMETHING HERE.
// $modx->sendRedirect($target_url);
}
else
{
$modx->sendErrorPage();
}
exit;
}
else
{
}
break;
default :
return; // stop here
break;
}
//------------------------
If you provide a full URL link to those pages and they are outside the MODx site (so the MODx .htaccess won’t take effect), you should get straight to them.
Thanks for the input. The files are inside the ModX domain and need to stay there. It’s good to know that it works for someone.
The only active parts of the htaccess file are these lines:
RewriteEngine On
RewriteBase /
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Is there some other setup parameter that I should change?
Thanks.
You could put an .htaccess file in the folder(s) holding the files with "rewrite engine off" in it if that wouldn’t cause you other problems. Otherwise, all URLS will end up as index.php?etc... and you won’t find your pages.
I think you could also give the pages a prefix and add rewrite rules to the site .htaccess for that prefix.
Why not just use a weblink?
That way they will still be part of any menus (if you want) under the same domain but separate from the CMS.
Content Creator and Copywriter
Thanks for the tip -- I’ll try adding a different htaccess file to the subfolders.
Spin,
all I can say is that I have separate pages that are not part of Modx, but are under my domain and in the same folder structure, and a weblink works fine.
I haven’t had to change the htaccess or anything else, so all I can say is it does work, for me at least.
My htaccess is the same as yours.
There must be something else going on.
What does it say for the url in the actual weblink in Modx?
Content Creator and Copywriter
It looks like the problem is that you can’t use the htaccess file to password protect a folder in a domain that’s managed by ModX. At least not the way I was doing it.
I was trying to access a folder that contained the following htaccess file:
AuthType Basic
AuthUserFile /sompath/somefolder/.htpasswd
AuthName "SomeName"
require valid-user
I guess ModX couldn’t access the folder and suppresses the authentication dialog that usually appears when you protect a folder. I’ll figure out another way to protect the folder, but in the meantime, at least I can access files in unprotected folders.
Thanks for all of the tips. This was my first post on a ModX forum, and I’m impressed at how responsive everyone was. Much appreciated.