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).
URL路由在非条件下
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
dongxu1875 2012-12-08 06:49关注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]解决 无用评论 打赏 举报