我是一名新程序员,目前正在学习php mvc。我正在从头开始构建框架/mvc 系统...现在我面临 .htaccess 的问题。
example.com = localhost // unable to post question for localhost link
我的申请网址是这样的...
http://example.com/mvc/index.php?go=test //test is a controller's name
By the help from .htaccess I cleaned the url to....
http://example.com/mvc/test
If a controller does not exists it shows an error view, which contains some error message.
http://example.com/mvc/doesnotexists But if I put "/" (forward slash) in the url... http://example.com/mvc/test/ it shows the error but does not load any css or js file.
I have also included controllers method in url...
http://example.com/mvc/test/viewresult If no matched method found in that controller show error message, it shows but same problem...no css nor js.
I have fully loaded css and js if I go through full url
http://example.com/mvc/index.php?go=doesnotexists/ and so on
I have tried several .htaccess rules but unable to get it work. Please help and thanks in advance.. My currrent .htaccess code...
<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'是你的 Controller ,而'param'是'test' Controller 的 Action 你可以使用
http://example.com/mvc/test/param
$_GET['go'] 将是 'test/param' 你需要爆炸它来获得'param' Action
关于php mvc 和 .htaccess url 重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11979579/
是否可以重写基本URL?例如而不是www.host.com/使用www.host.com/blah/作为一个基本的url等等:get'/'do...end适用于www.host.com/blah/我可以附加到我的所有路线'/blah/..'但任何gem等。也将无法工作。这可以在Rails中轻松完成,我也想在Sinatra中使用它。 最佳答案 我为此使用了Rack中间件rack-rewrite我对此很满意:)useRack::Rewritedorewrite%r{^/\w{2}/utils},'/utils'rewrite%r{^/\
我有一个要在IRB中运行的小程序。它最终输出一些看起来像数组的东西,尽管从技术上讲不是数组。(该类继承自数组。)问题是,当我执行此类的实例时,例如example=Awesome.new(1,2,3),我写了“putsexample”,IRB的默认行为是将example的每个元素放在它自己的行上。所以代替[1,2,3](这是我想要的),IRB弹出这个。123有没有一种巧妙的方法来覆盖这个特殊类的puts方法?我试过了,但没用。defputsself.to_aend知道我做错了什么吗?更新:所以我尝试了这个,但没有成功。defto_sreturnselfend所以当我在IRB中并且我只输入
我不知道正确的术语。我试图用谷歌搜索它,但由于这个原因找不到任何东西。我正在编写一个Ruby库,我想重写这些函数,以便它们像下面那样工作,因为我更喜欢它的可读性(在一个block内?)我有一个函数可以做到这一点@dwg=Dwg.new("test.dwg")@dwg.line([0,0,0],[1,1,0])@dwg.save我想重写它,让它像这样工作Dwg.new("test.dwg")doline([0,0,0],[1,1,0])saveend你能概述一下我处理这件事的方法吗? 最佳答案 您可以定义Dwg的初始化程序来获取一个b
根据docs,Array.include?在对象上使用==比较。我来自Java,其中此类事情(通常)使用.equals()完成,对于特定对象很容易覆盖。如何在Ruby中覆盖==以允许我为我的特定对象指定Array.include?的行为? 最佳答案 在Ruby中,==只是一个方法(顶部有一些语法糖,允许您编写foo==bar而不是foo.==(bar))并且你覆盖==就像你使用任何其他方法一样:classMyClassdef==(other_object)#returntrueifselfisequaltoother_object,
给定这段代码:classACONST='A'definitializeputsCONSTendendclassB'A'B.new#=>'A'我希望B使用CONST='B'定义,但我不知道如何使用。有什么想法吗?问候汤姆 最佳答案 classACONST='A'definitializeputsself.class::CONSTendendclassB'A'B.new#=>'B' 关于ruby-如何在继承类中使用重写常量,我们在StackOverflow上找到一个类似的问题:
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭7年前。Improvethisquestion我一直在试验,发现我喜欢重新定义Object的to_s方法。这是一个坏主意还是一个好的做法?
我正在尝试覆盖jquery小部件内的方法。该方法可在第122行找到,地址为https://github.com/got5/tapestry5-jquery/blob/master/src/main/resources/org/got5/tapestry5/jquery/validation.js。我想修改第141行的html输出我尝试将以下内容添加到我的自定义js类中,但没有成功。如果有人能解释如何做到这一点,我将不胜感激。(function($){$.widget("ui.tapestryFieldEventManager",{showValidationMessage:functi
这个问题在这里已经有了答案:Howtodeepmergeinsteadofshallowmerge?(47个回答)关闭5年前。我想合并两个对象,覆盖属性但保留未被覆盖的属性。示例:我有以下对象consttheme={colors:{base:'#fff',accent:'#ff0000'}}和constthemeOverride={colors:{accent:'#ff8900'}}并想将这些合并在一起得到constnewTheme={colors:{base:'#fff',accent:'#ff8900'}}
我已经努力了好几个小时,试图设置真正重写url的适当缩小。我用过useref和usemin,它们在扫描html、聚合所有JS和CSS并输出到一个文件方面做得很好。但是,对于我来说,我无法使url重写以正常工作。我的结构很简单:\rootindex.htmlapplication.css//minifiedapplication.js//minified\vendor\bootstrap\fonts//fontfilesherebootstrap.css//pre-minifiedbootstrap.css使用相对url引用字体文件-font/bootstrap_font.ttf当boo
我的urlrewrites有问题-每当我指向要重写的页面时,它都无法显示,因为它还将规则应用于我网页中引用的css和js文件。为了尝试解决这个问题,我在css和js中加入了一个完全合格的路径-当我尝试访问浏览器挂起的重写页面时,这在任何尚未应用重写的页面上都可以正常呈现。有没有人遇到过类似的事情,如果有,你有解决办法吗?感谢任何帮助。尝试在网站上查看类似问题,但到目前为止没有任何帮助。在我的网页中:它正在对这些应用重写并尝试查找/myapplicationname/Team/Styles/MainStyle.css以及与JS文件类似的内容。 最佳答案