我正在尝试转换查询字符串;
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 带来了大量结果。
在另一个 stackoverflow 回答之后,我在我的 .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>
我在 .htaccess 文件中的代码不起作用,我刷新页面并没有任何反应。隐藏 index.php 的代码虽然有效。有谁知道为什么?