Apache - friendly urls and mod_rewrite issue

NOTE: I am working with Phalcon tutorial -
http://docs.phalconphp.com/en/latest/reference/apache.html

This is Apache on Windows.

I have a web page that I can browse to with no issues -
https://localhost:8443/tutorial/index.php

I have set up the rewrite rules in the httpd.conf file (not using .htaccess) -

<IfModule mod_rewrite.c>

    <Directory "c:/Apache24/htdocs/tutorial">
        RewriteEngine on
        RewriteRule  ^$ public/    [L]
        RewriteRule  (.*) public/$1 [L]
    </Directory>

    <Directory "c:/Apache24/htdocs/tutorial/public">
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
    </Directory>

</IfModule>

But when I browse to https://localhost:8443/tutorial/
I get the directory listing of the public folder -

Index of /tutorial/public

Parent Directory
css/
img/
index.php
js/

It takes me to the public folder so it seems that part of the rewrite is working.

Any ideas what I'm missing?

Thanks,

Kevin.
kevinvw1Asked:
Who is Participating?
 
Phil PhillipsDirector of DevOps & Quality AssuranceCommented:
Yes, that rule is taking all requests and letting index.php handle it (if a file/directory doesn't exist for that request)

However, I believe this line might be keeping the rule from triggering for the "/" request:
RewriteCond %{REQUEST_FILENAME} !-d

Open in new window


Since the root directory exists, it looks like it's defaulting back to apache's index handling.  Specifying the "DirectoryIndex" should get you to your expected behavior.  If you don't want to exclude existing directories from that rewrite rule, you can also comment out the line I mentioned.
0
 
Phil PhillipsDirector of DevOps & Quality AssuranceCommented:
You need to tell apache what file to use for the index page.  You can add something like this to your config:

DirectoryIndex index.php

Open in new window

0
 
kevinvw1Author Commented:
Thanks.  But isn't that what the 2nd rewrite rule is supposed to do?

RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
0
 
Ray PaseurCommented:
Check the notes at the bottom of this page:
http://laravel.com/docs/4.2

Laravel routes everything through index.php and uses its own routes.php file to determine the actual targets for RESTful routing, based on the URLs of the request.  Very elegant and simple!
0
 
kevinvw1Author Commented:
@Phil,  I removed that RewriteCond line and it worked.  I am still not sure why.

Maybe it is my Apache on Windows? Or something else I have configured incorrectly.

@Ray - I am having same issue with Laravel -

Laravel has the pretty much the exact same rewrite -

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

AFAIK,  both Laravel and Phalcon rely on their own custom routing.

I am going to try this on Linux and see if it behaves as expected.

Thanks for all the help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.