I want to call a specific module when url doesnot contail certain words. Eg.: if url is www.abc.com/articles/a
, I want to route it normally. If url is www.abc.com
, it should be calling default module. But if url is www.abc.com/qw/asw
, it should call blog module (Controller).
You can cut out and checked the url this way:
$subdir = substr(realpath(dirname(__FILE__)), strlen(realpath($_SERVER['DOCUMENT_ROOT'])));
$tmp_array = explode('?', trim($_SERVER['REQUEST_URI']));
$uri = str_replace($subdir, '', $tmp_array[0]);
$uri = ltrim($uri, '/');
$URIParts = explode("/", $uri);
$URIPartsCount = count($URIParts);
if( $URIPartsCount>0 && in_array($URIParts[0],$pages) )
{
$uripart = $URIParts[0];
if( in_array($uripart,$somearray) )
{
$page = $uripart;
}
...
else
{
$page = "index";
}
}
else
{
$page = "index";
}
if( $URIPartsCount>1 )
{
$todo = $URIParts[1];
}
else
{
$todo = "";
}
.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [QSA]
I think you are doing this backwards. Why not route specific URL patterns to the module you would like them to go to? Much easier.