我有一个域和一个名为“sub”的子文件夹。在“sub”中是 index.php,其中包含:
$page = $_GET['page'];
switch ($page)
{
case "main":
echo "main";
break;
case "task_orders":
echo "task_orders";
break;
case "team_members":
echo "team_members";
break;
case "team_experience":
echo "team_experience";
break;
case "quality_assurance":
echo "quality_assurance";
break;
case "geographical_support":
echo "geographical_support";
break;
case "contact":
echo "contact";
break;
default:
echo "main";
}
我在“sub”中的 htaccess 是:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^sub/([^/\.]+)/?$ index.php?page=$1 [L]
当我点击一个看起来像这样的链接时:
<li><a href="/sub/main" title="Main" class="current">Main</a></li>
<li><a href="/sub/task_orders" title="Task Orders">Task Orders</a></li>
<li><a href="/sub/team_members" title="Team Members">Team Members</a></li>
<li><a href="/sub/team_experience" title="Team Experience">Team Experience</a></li>
<li><a href="/sub/quality_assurance" title="Quality Assurance Program">Quality Assurance</a></li>
<li><a href="/sub/geographical_support" title="Geographical Support">Geographical Support</a></li>
<li><a href="/sub/contact" title="Points of Contact">Points of Contact</a></li>
我得到一个未找到的页面而不是回显我所在的页面,有什么想法吗?
我也试过:
RewriteRule ^/sub/([^/\.]+)/?$ /sub/index.php?page=$1 [L]
同样的结果
最佳答案
你快到了。您不想在编写 RewriteRule 时指定前导 /。
在文档根目录中:
RewriteEngine on
RewriteRule ^sub/([^/\.]+)/?$ /sub/index.php?page=$1 [L]
来自/sub 文件夹:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
关于php - 子目录的mod_rewrite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6668423/
我正在使用active_admin,我在Rails3应用程序的应用程序中有一个目录管理,其中包含模型和页面的声明。时不时地我也有一个类,当那个类有一个常量时,就像这样:classFooBAR="bar"end然后,我在每个必须在我的Rails应用程序中重新加载一些代码的请求中收到此警告:/Users/pupeno/helloworld/app/admin/billing.rb:12:warning:alreadyinitializedconstantBAR知道发生了什么以及如何避免这些警告吗? 最佳答案 在纯Ruby中:classA
是否可以在应用程序中包含的gem代码中知道应用程序的Rails文件系统根目录?这是gem来源的示例:moduleMyGemdefself.included(base)putsRails.root#returnnilendendActionController::Base.send:include,MyGem谢谢,抱歉我的英语不好 最佳答案 我发现解决类似问题的解决方案是使用railtie初始化程序包含我的模块。所以,在你的/lib/mygem/railtie.rbmoduleMyGemclassRailtie使用此代码,您的模块将在
在我让另一个人重做我的前端UI之前,我的Rails应用程序运行平稳。我已经尝试解决此错误3天了。这是错误:Nosuchfileordirectory-identifyExtractedsource(aroundline#59):575859606162@post=Post.find(params[:id])authorize@postif@post.update_attributes(post_params)flash[:notice]="Postwasupdated."redirect_to[@topic,@post]else{"utf8"=>"✓","_method"=>"patc
我正在尝试以一种更类似于普通RubyGem结构的方式构建我的Sinatra应用程序。我有以下文件树:.├──app.rb├──config.ru├──Gemfile├──Gemfile.lock├──helpers│ ├──dbconfig.rb│ ├──functions.rb│ └──init.rb├──hidden│ └──Rakefile├──lib│ ├──admin.rb│ ├──api.rb│ ├──indexer.rb│ ├──init.rb│ └──magnet.rb├──models│ ├──init.rb│ ├──invite.rb│ ├─
我想编写一个ruby脚本来递归复制目录结构,但排除某些文件类型。因此,给定以下目录结构:folder1folder2file1.txtfile2.txtfile3.csfile4.htmlfolder2folder3file4.dll我想复制这个结构,但不包含.txt和.cs文件。因此,生成的目录结构应如下所示:folder1folder2file4.htmlfolder2folder3file4.dll 最佳答案 您可以使用查找模块。这是一个代码片段:require"find"ignored_extensions=[".cs"
我正在使用Rails3.2.2并希望递归加载某个目录中的所有代码。例如:[Railsroot]/lib/my_lib/my_lib.rb[Railsroot]/lib/my_lib/subdir/support_file_00.rb[Railsroot]/lib/my_lib/subdir/support_file_01.rb...基于谷歌搜索,我试过:config.autoload_paths+=["#{Rails.root.to_s}/lib/my_lib/**"]config.autoload_paths+=["#{Rails.root.to_s}/lib/my_lib/**/"
我是Ruby的新手,我正在尝试以如下方式打开文件:#!/usr/bin/envrubydata_file='~/path/to/file.txt'file=File.open(data_file,'r')但是我得到“没有这样的文件或目录”(该文件确实存在于该目录中)。如果我将该文件路径作为命令行参数,它会起作用,例如:#!/usr/bin/envrubyfile=File.open(ARGV[0],'r')然后从命令行运行,如:rubyscript.cgi~/path/to/file.txt关于如何让它以第一种方式工作的任何想法? 最佳答案
这是我在ChefRecipe中的一blockRuby:#ifdatadirdoesn'texist,moveoverthedefaultoneif!File.exist?("/vol/postgres/data")execute"mv/var/lib/postgresql/9.1/main/vol/postgres/data"end结果是:Executingmv/var/lib/postgresql/9.1/main/vol/postgres/datamv:inter-devicemovefailed:`/var/lib/postgresql/9.1/main'to`/vol/post
我对RoR有点陌生,我想要一个结构化的目录,因为项目可能会变大我不想让所有的Controller直接进入controllers目录。我想要一些东西app/controllers/application_controller.rbgroupa/athing_controller.rbathing2_controller.rbgroupb/bthing_controller.rb然而,当我在routes.rb中放置以下内容时:get'athing',:to=>"groupa/athing#index"我在localhost:3000/athing/上收到以下错误:superclassmis
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭9年前。我来自C、php和bash背景,很容易学习,因为它们都有相同的C结构,我可以将其与我已经知道的联系起来。然后2年前我学了Python并且学得很好,Python对我来说比Ruby更容易学。然后从去年开始,我一直在尝试学习Ruby,然后是Rails,我承认,直到现在我还是学不会,讽刺的是那些打着简单易学的烙印,但是对于我这样一个老练的程序员来说,我只是无法将它