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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Phil PhillipsDevOps ArchitectCommented:
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
Phil PhillipsDevOps ArchitectCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.