我继续了解htaccess。我还没有阅读有关此问题的文档中有用的任何内容。这是我的.htaccess:
RewriteEngine On
RewriteBase /
# e.g. Rewrite 'contact' to 'index.php/main/lessons'
RewriteRule ^contact$ index.php/main/lessons
规则不起作用,就好像重写甚至没有发生一样。网址没有变化,只是得到一个空白页面。我想将任何请求重定向到/contact
到/index.php/main/contact
。但是,当我添加[R=301]
标志时,
有用。我在chrome开发人员工具中看到了永久重定向请求,最后我在最右边的页面。有什么帮助吗?
感谢。
这是我在LogLevel alert rewrite:trace3
中使用httpd.conf
从错误日志中获取的内容:
[Sat Jan 24 21:50:29.243747 2015] [rewrite:trace3] [pid 5028:tid 908] mod_rewrite.c(475): [client ::1:61103] ::1 - - [mysite/sid#73702837d0] [rid#73716b5310/initial] [perdir C:/Sites/mysite/] applying pattern '^contact$' to uri 'contact'
[Sat Jan 24 21:50:29.243747 2015] [rewrite:trace2] [pid 5028:tid 908] mod_rewrite.c(475): [client ::1:61103] ::1 - - [mysite/sid#73702837d0] [rid#73716b5310/initial] [perdir C:/Sites/mysite/] rewrite 'contact' -> 'index.php/main/lessons'
[Sat Jan 24 21:50:29.243747 2015] [rewrite:trace3] [pid 5028:tid 908] mod_rewrite.c(475): [client ::1:61103] ::1 - - [mysite/sid#73702837d0] [rid#73716b5310/initial] [perdir C:/Sites/mysite/] add per-dir prefix: index.php/main/lessons -> C:/Sites/mysite/index.php/main/lessons
[Sat Jan 24 21:50:29.243747 2015] [rewrite:trace2] [pid 5028:tid 908] mod_rewrite.c(475): [client ::1:61103] ::1 - - [mysite/sid#73702837d0][rid#73716b5310/initial] [perdir C:/Sites/mysite/] trying to replace prefix C:/Sites/mysite/ with /
[Sat Jan 24 21:50:29.243747 2015] [rewrite:trace1] [pid 5028:tid 908] mod_rewrite.c(475): [client ::1:61103] ::1 - - [mysite/sid#73702837d0][rid#73716b5310/initial] [perdir C:/Sites/mysite/] internal redirect with /index.php/main/lessons [INTERNAL REDIRECT]
[Sat Jan 24 21:50:29.248751 2015] [rewrite:trace3] [pid 5028:tid 908] mod_rewrite.c(475): [client ::1:61103] ::1 - - [mysite/sid#73702837d0][rid#737168f168/initial/redir#1] [perdir C:/Sites/mysite/] add path info postfix: C:/Sites/mysite/index.php -> C:/Sites/mysite/index.php/main/lessons
[Sat Jan 24 21:50:29.248751 2015] [rewrite:trace3] [pid 5028:tid 908] mod_rewrite.c(475): [client ::1:61103] ::1 - - [mysite/sid#73702837d0][rid#737168f168/initial/redir#1] [perdir C:/Sites/mysite/] strip per-dir prefix: C:/Sites/mysite/index.php/main/lessons -> index.php/main/lessons
[Sat Jan 24 21:50:29.248751 2015] [rewrite:trace3] [pid 5028:tid 908] mod_rewrite.c(475): [client ::1:61103] ::1 - - [mysite/sid#73702837d0][rid#737168f168/initial/redir#1] [perdir C:/Sites/mysite/] applying pattern '^contact$' to uri 'index.php/main/lessons'
[Sat Jan 24 21:50:29.248751 2015] [rewrite:trace1] [pid 5028:tid 908] mod_rewrite.c(475): [client ::1:61103] ::1 - - [mysite/sid#73702837d0][rid#737168f168/initial/redir#1] [perdir C:/Sites/mysite/] pass through C:/Sites/mysite/index.php
[Sat Jan 24 21:50:29.249748 2015] [rewrite:trace3] [pid 5028:tid 908] mod_rewrite.c(475): [client ::1:61103] ::1 - - [mysite/sid#73702837d0][rid#73716af2e0/subreq] [perdir C:/Sites/mysite/] add path info postfix: C:/Sites/mysite/main -> C:/Sites/mysite/main/lessons
[Sat Jan 24 21:50:29.249748 2015] [rewrite:trace3] [pid 5028:tid 908] mod_rewrite.c(475): [client ::1:61103] ::1 - - [mysite/sid#73702837d0][rid#73716af2e0/subreq] [perdir C:/Sites/mysite/] strip per-dir prefix: C:/Sites/mysite/main/lessons -> main/lessons
[Sat Jan 24 21:50:29.249748 2015] [rewrite:trace3] [pid 5028:tid 908] mod_rewrite.c(475): [client ::1:61103] ::1 - - [mysite/sid#73702837d0][rid#73716af2e0/subreq] [perdir C:/Sites/mysite/] applying pattern '^contact$' to uri 'main/lessons'
[Sat Jan 24 21:50:29.249748 2015] [rewrite:trace1] [pid 5028:tid 908] mod_rewrite.c(475): [client ::1:61103] ::1 - - [mysite/sid#73702837d0][rid#73716af2e0/subreq] [perdir C:/Sites/mysite/] pass through C:/Sites/mysite/main
我还应该注意到我正在使用CodeIgniter。
答案 0 :(得分:0)
使用代码点火器,您只需在" application / config / routes.php"
中定义重定向只需添加以下行:
$route['contact'] = 'main/contact';