php mvc和.htaccess url重写

Sha*_*kil 4 php apache .htaccess url-routing

我是一名新程序员,目前正在学习php mvc.我正在从头开始构建一个框架/ mvc系统......现在我遇到了.htaccess的问题.

    example.com = localhost // unable to post question for localhost link
Run Code Online (Sandbox Code Playgroud)

我的申请网址是这样的......

        http://example.com/mvc/index.php?go=test //test is a controller's name

在.htaccess的帮助下,我清理了网址....

        http://example.com/mvc/test

如果控制器不存在,则显示错误视图,其中包含一些错误消息.

        http://example.com/mvc/doesnotexists
Run Code Online (Sandbox Code Playgroud) 但是如果我把"/"(正斜杠)放在网址中......
        http://example.com/mvc/test/
Run Code Online (Sandbox Code Playgroud) 它显示错误但不加载任何css或js文件.

我还在网址中包含了控制器方法......

        http://example.com/mvc/test/viewresult
Run Code Online (Sandbox Code Playgroud) 如果在该控制器中找不到匹配的方法显示错误消息,则显示但是同样的问题...没有css也没有js.

如果我通过完整网址,我已经完全加载了css和js

        http://example.com/mvc/index.php?go=doesnotexists/
Run Code Online (Sandbox Code Playgroud) 等等

我已经尝试了几个.htaccess规则,但无法让它工作.请提前帮助和感谢..我的currrent .htaccess代码......

<IfModule mod_rewrite.c>  

    # Turn on 
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l

    #RewriteCond %{REQUEST_URI} !^/assets/
    #RewriteCond $1 !^(favicon\.ico|favicon\.png|media|robots\.txt|crossdomain\.xml|.*\.css|.*\js)

    RewriteRule ^(.+)$ index.php?go=$1 [QSA,L]

   # Generic 404 for anyplace on the site  
   # ...  

</IfModule>  
Run Code Online (Sandbox Code Playgroud)

Lou*_*ast 5

css和js的最佳解决方案是使用完整路径:

http://example.com/mvc/assets/style.css

http://cdn.example.com/style.css
Run Code Online (Sandbox Code Playgroud)

并重写

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?go=$1
Run Code Online (Sandbox Code Playgroud)

如果你的'test'是你的控制器,'param'是你可以使用的'test'控制器的动作

http://example.com/mvc/test/param
Run Code Online (Sandbox Code Playgroud)

$ _GET ['go']将是'test/param'你需要将它爆炸以获得'param'动作