【发布时间】:2012-12-28 08:29:12
【问题描述】:
我正在尝试转换查询字符串;
http://atwd/books/course?course_id=CC100&format=XML&submit=Submit
进入一个段URI;
http://atwd/books/course/CC100/XML
我在 CodeIgniter 工作。
我正在查看一个 stackoverflow 答案,该答案说要检查 CodeIgniter 的 URL 段指南,但我认为没有任何关于如何将查询字符串转换为段 URI 的信息。然而,有一种方法可以将段 URI 转换为查询字符串,这也带来了来自 Google 的大量结果。
在another stackoverflow answer 之后,我在我的 .htaccess 文件中尝试了这个,但似乎没有任何效果
RewriteCond %{QUERY_STRING} ^course_id\=([^&]+)\&format\=([^&]+)$
RewriteRule ^$ /course/%1/format/%2 [R,L]
在我的整个 .htaccess 文件中都有这个;
<IfModule mod_rewrite.c>
RewriteEngine on
#Source: http://codeigniter.com/user_guide/general/urls.html
#Removal of index.php
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php?route/$1 [L]
#Source: https://stackoverflow.com/questions/3420204/htaccess-get-url-to-uri-segments
#Format Course function requests
RewriteBase /
RewriteCond %{QUERY_STRING} ^course_id\=([^&]+)\&format\=([^&]+)$
RewriteRule ^$ /course/%1/format/%2 [R,L]
</IfModule>
这是在我的 Codeigniter 的根目录screenshot
我在 .htaccess 文件中的代码不起作用,我刷新页面但没有任何反应。隐藏 index.php 的代码虽然有效。有谁知道为什么?
【问题讨论】:
-
您想将此
http://atwd/books/course?course_id=CC100&format=XML&submit=Submit重定向到此http://atwd/books/course/CC100/XML,还是相反? ¿ 其他示例和说明是什么? -
我不认为这是因为在您的重写条件下您将其称为 course_id 而在重写规则中您将其称为 course 是吗?
-
@faa 我不需要重定向那个 URL。我只需要将 URI 格式化为段,而不是现在的查询字符串。
-
@Rick_Calder 我认为“课程”文本只会输出到浏览器,百分比代表重写条件。
标签: php .htaccess codeigniter uri