web项目的htaccess和文件结构

时间:2015-01-11 21:29:28

标签: php .htaccess url web project

我的网络项目中有这个结构:

domain.com

    -index.php

    frontend

        .htaccess
        -index.php
        -home.php
        -404.php
        -new_site.php

        account

            -index.php
            -new_site.php

    backend

        -backendfiles.php
        -etc..

我的档案,

domain.com/index.php:

include ( 'frontend/index.php' );

domain.com/frontend/.htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?values=$1 [L]
</IfModule>

domain.com/frontend/index.php:

$str = $_GET[ 'values' ];
$str = str_replace( '../', '', $str );

$vars = explode( '/', $str );
$path = '';
foreach( $vars as $var ) {
    $p = strpos( $var, ':' );
    if( $p == 0  ) {
        $path .= $var . '/';
        continue;
    }
    $_GET[ sub_str( $var, 0, $p ) ] = sub_str( $var, $p + 1 );
}

if( $path ) {

     // File
     $file = $path . '.php';
     if( file_exists( $file ) ) {
         include( $file );
         exit;
     }

     // Direction
     $file = $path . '/index.php';
     if( file_exists( $file ) ) {
         include( $file );
         exit;
     }

     // Page not found
     // include( '404.php' );

}

// Default Page
include( 'home.php' );

我尝试了什么...

当我打电话时:

domain.com

=&GT;从domain.com/frontend/home.php =&gt;加载内容作品

当我打电话时:

domain.com/new_site

=&GT;从domain.com/frontend/new_site.php =&gt;加载内容不起作用

当我打电话时:

domain.com/account

=&GT;从domain.com/frontend/account/index.php =&gt;加载内容不起作用

当我打电话时:

domain.com/account/new_site

=&GT;从domain.com/frontend/account/new_site.php =&gt;加载内容不起作用

任何人都可以帮我这个吗?

我的结构是好的还是应该改变它?

问候和感谢!

0 个答案:

没有答案