Ok could not get any of the above info (links) to work from my end (in regards to using custom routers etc) because i think my extension is not using any collections from the database as its just a landing page so wont have index/index/id values etc.
So went with a dirty hack to do the job for now. See below.
etc/config.xml (observer event when admin field setting saved)
<config>
...
<frontend>
<routers>
<myextension>
<use>standard</use>
<args>
<module>Mycompany_Myextension</module>
<frontName>myextension</frontName>
</args>
</myextension>
</routers>
...
</frontend>
<global>
...
<events>
<admin_system_config_changed_section_myextension>
<observers>
<myextension>
<type>singleton</type>
<class>myextension/observer</class>
<method>observersave</method>
</myextension>
</observers>
</admin_system_config_changed_section_myextension>
</events>
...
</global>
</config>
Model/Observer.php (Save a URL Rewrite) (EDITED)
public function observersave(Varien_Event_Observer $observer)
{
#remove the old urlrewrite
$url = Mage::getStoreConfig('myextension/general/url');
$uldURLCollection = Mage::getModel('core/url_rewrite')->getResourceCollection();
$uldURLCollection->getSelect()
->where('id_path=?', 'myextension');//EDIT: so overwrites on each save
$uldURLCollection->setPageSize(1)->load();
if ( $uldURLCollection->count() > 0 ) {
$uldURLCollection->getFirstItem()->delete();
}
#add url rewrite
$modelURLRewrite = Mage::getModel('core/url_rewrite');
$modelURLRewrite->setIdPath('myextension/'.strtolower($url))
->setTargetPath('myextension/index/index/id/'.$url.'')
->setOptions('')
->setDescription('New URL - Created as a new setting was saved')
->setRequestPath('myextension/url/'.$url.'');//EDIT: added extra rewrite url paths so rewrite can never conflict if admin setting field is set to a "key default url" like "admin" or "checkout" or "contacts" etc
$modelURLRewrite->save();
}
controllers/IndexController.php (redirects if no ID...) (EDITED)
public function preDispatch()
{
//$url = Mage::getStoreConfig('myextension/general/url');
if ( !strstr($this->getRequest()->getRequestUri(), 'myextension/index/index/id') ) {
parent::preDispatch();
}
}
public function indexAction()
{
$url = Mage::getStoreConfig('myextension/general/url');
if ( trim($this->getRequest()->getParam('id')) == '' ) {
$this->_redirect('/');//Edit: changed redirect to root
} else {
$id = $this->getRequest()->getParam('id');
if($id == $url) {
$this->loadLayout( array(
'default',
'myextension_index_index'
));//EDIT: added if statement to see if myextension/index/index/id matched admin setting, if not redirect to root
$this->renderLayout();
}else{
$this->_redirect('/');//Edit: changed redirect to root
}
}
}
so at this point i have URLs at: (EDITED)
site.com/myextension/url/myadminfieldvalue
&
site.com/myextension/index/index/id/myadminfieldvalue
(EDITED)
but in template/myextension/myextension.phtml
<?php if($current_url == ''.$base_url.'myextension/index/index'){ ?>
<p>Disabled cause i dont really want info at this url..</p>
<?php }else{ ?>
<p>show data because your accessing myextension/index/index via the rewrite /myextension/url/myadminfieldvalue.</p>
<?php } ?>
A bit more work is needed to achieve what i want but for now it works for me and hope others may find this useful.