Apache - friendly urls and mod_rewrite issue

NOTE: I am working with Phalcon tutorial -

This is Apache on Windows.

I have a web page that I can browse to with no issues -

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


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

Index of /tutorial/public

Parent Directory

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

Any ideas what I'm missing?


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.
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

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

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

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!
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.
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.