PatrickLouys / no-framework-tutorial

A small tutorial to show how to create a PHP application without a framework.
MIT License
1.53k stars 186 forks source link

.htaccess File for Apache Users #31

Closed HassanAlthaf closed 8 years ago

HassanAlthaf commented 9 years ago

You've missed out the need to use an .htaccess file for Apache users for the Front Controller pattern. The one which works for me is:

Options -MultiViews ``` RewriteEngine On # Redirect Trailing Slashes... RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] ```
HassanAlthaf commented 9 years ago

Argh, the parts are lost. Refer to this pastebin: http://pastebin.com/6HX2y2Be

PatrickLouys commented 9 years ago

This is very server specific and not really relevant to the built in server that the tutorial uses. I will consider adding it though and if I do that I'll also add a nginx example config.

HassanAlthaf commented 9 years ago

@PatrickLouys Well not everyone is gonna exactly run the built in PHP server like you. :P

Zvax commented 8 years ago

+1 for having to fix that part myself. Imo, no need to clutter this great tutorial with apache or nginx specific code, those are well covered elsewhere on the interwebs.

PatrickLouys commented 8 years ago

Agreed

oneum-zz commented 8 years ago

Like I asked for help in #37 there is nothig wrong with the guide except I was using the apache2 httpd and I need the .htaccess for this example.

@HassanAlthaf can you please repost the .htaccess content please?

EDIT - Here it is, if one need it like I did:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>