加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php mvc和.htaccess url重写

发布时间:2020-12-13 17:20:40 所属栏目:PHP教程 来源:网络整理
导读:我是一个新的程序员,目前正在学习 PHP的MVC.我从头开始建立一个框架/ MVC系统……现在我面临的问题的.htaccess. example.com = localhost // unable to post question for localhost link 我的应用程序的URL是这样的… http://example.com/mvc/index.php?go=
我是一个新的程序员,目前正在学习 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’动作

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读