微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php mvc和.htaccess url重写

我是一个新的程序员,目前正在学习 PHP的MVC.我从头开始建立一个框架/ MVC系统……现在我面临的问题的.htaccess.

example.com = localhost // unable to post question for localhost link

我的应用程序的URL是这样的…

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

通过从.htaccess中的帮助下,我清理的URL ….

        http://example.com/mvc/test

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

        http://example.com/mvc/doesnotexists

 但是,如果我把“/”(正斜杠)的网址…

        http://example.com/mvc/test/

 它显示错误,但不加载任何CSS或JS文件.

我也包含在URL控制器方法

        http://example.com/mvc/test/viewresult

 如果在控制器显示错误消息,没有发现匹配的方法,它显示但同样的问题…没有CSS也不js的.

我已经完全加载CSS和JS如果我经历完整的URL

        http://example.com/mvc/index.PHP?go=doesnotexists/

  等等

我尝试了好几种的.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>

解决方法

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

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

http://cdn.example.com/style.css

并重写

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.PHP?go=$1

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

http://example.com/mvc/test/param

$_GET [‘go’]将是’test / param’你需要爆炸才能获得’param’动作

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐