2

My quest to understand htaccess continues. I haven't read anything useful in the documentation for this problem. This is my .htaccess:

RewriteEngine On
RewriteBase /

# e.g. Rewrite 'contact' to 'index.php/main/lessons'
RewriteRule ^contact$ index.php/main/lessons

The rule does not work, it is as if the rewrite doesn't even take place. The url is unchanged as just get a blank page. I want to redirect any request to /contact to /index.php/main/contact. However, when I add the [R=301] flag, it works. I see the permanent redirect request in chrome developer tools and I end up at the right page. Any help?

Thanks.

This is what I get from my error log with LogLevel alert rewrite:trace3 in my 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

I should also note that I am using CodeIgniter.

9
  • The URL (that you see in the browser address bar) is supposed to stay “unchanged” if you only issue an internal rewrite, and not an external redirect. As to why you get a “blank page”, that could be due to any kind of error in your script.
    – CBroe
    Jan 24, 2015 at 6:42
  • 2
    Do you have any other rules? I would add the [L] flag. You might want to follow the instructions on how to log/debug to figure out what exactly Apache is doing. You are working with path-info, but I thought it was possible to internally rewrite with path info.
    – Sumurai8
    Jan 24, 2015 at 6:42
  • @CBroe I know that, but it does not explain why I am getting this behaviour.
    – Neurion
    Jan 24, 2015 at 7:19
  • @BelegNeurion: Can you show your full .htaccess in question
    – anubhava
    Jan 24, 2015 at 7:54
  • @anubhava That is my entire htaccess file at the moment. After coming across this problem I backed up my original and replaced it with the file in the description so I could narrow down the problem.
    – Neurion
    Jan 24, 2015 at 8:23

1 Answer 1

0

Using code igniter you can just define redirections in "application/config/routes.php"

Just add this line:

$route['contact'] = 'main/contact';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.