Link to home
Start Free TrialLog in
Avatar of kevinvw1
kevinvw1

asked on

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.
Avatar of Phil Phillips
Phil Phillips
Flag of United States of America image

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

Avatar of kevinvw1
kevinvw1

ASKER

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

RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
ASKER CERTIFIED SOLUTION
Avatar of Phil Phillips
Phil Phillips
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@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.