漂亮的URL和mod_rewrite

时间:2011-03-09 07:53:13

标签: php apache codeigniter mod-rewrite

我似乎无法完成这项工作 - 而且我很确定真正的问题是我只是自己主宰它,所以我希望一双新眼睛可以帮助我。

我不想做的是将几个应用程序附加到我的系统上。 目前,根文件夹中已存在一个网站,但我不想在CI安装中使用微网站/电源格式。

我的mod_rewrite看起来像这样:

RewriteCond %{REQUEST_URI} ^/(powerformat1|powerformat2)/?$
RewriteRule ^(.*)$ powerformats/index.php/$1 [L] 

虽然正确地获取CI index.php,但在尝试访问example.org/powerformat1或example.org/powerformat2时,我会给出CI的404页面。

似乎无论我尝试重写规则,我都会得到404页面或者根本没有。

任何见解?

- 编辑 -

我认为我的问题是CI实际上将'powerformat1'字符串作为第一个段传递。这就是我需要避免的。但是不能通过mod_rewrite解决这个问题吗?

2 个答案:

答案 0 :(得分:1)

您错过了RewriteEngine On吗?

答案 1 :(得分:1)

您可以尝试使用相应的查询字符串直接链接到该文件

RewriteRule ^(.*)$ /powerformats/index.php?somequery=$1 [L]
(您可能需要更改斜杠,请参阅下文)

可能是这样的:

访问/powerformat1/ 可能会改写为 powerformats/index.php//powerformat1/

你可以试试     RewriteRule ^/(.*)/$ /powerformats/index.php/$1 [L]
或斜线的其他变化:
    RewriteRule ^/(.*)/$ /powerformats/index.php/$1/ [L]