2

I am building my own PHP MVC framework from scratch on ubuntu. .htaccess file is not properly working in it. The folder structure and the .htaccess file content are as bellow.

Folder Structure

/MyMVCProject
/controllers
     index.php
     help.php
/libs
/modles
/views
.htaccess
index.php

.htaccess File content

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

When I type localh0st/MyMVCProject/help it gives me the following error.

Not Found
The requested URL /MyMVCProject/help was not found on this server.
Apache/2.2.22 (Ubuntu) Server at localh0st Port 80

And I'm sure I have enabled mod_rewrite.

4
  • Might it be, that you made mistake here localh0st and actually you were trying to do localhost? Commented Apr 20, 2013 at 10:00
  • Hi Eugene I purposely did that when I posted the question on "stackoverflow". Commented Apr 20, 2013 at 11:55
  • Okey. Have you tried my suggestion? Commented Apr 20, 2013 at 15:30
  • What URL is your application expecting? For instance, a request for localh0st/MyMVCProject/help would result in the request be routed to: index.php?url=MyMVCProject/help - is that correct? Commented Sep 4, 2016 at 18:30

4 Answers 4

1

Try to do it this way and from $_REQUEST array you can get url parameter and handle it in your index.php file.

Also for testing purpose add

echo <pre>;
print_r($_REQUEST);
echo </pre>;

at first lines of index.php

<ifModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_URI} ^/$ [NC]
    RewriteRule ^(.*)$ /$1 [R=301,L]
</ifModule>
Sign up to request clarification or add additional context in comments.

Comments

1

Try following RewriteRule (Copied and bit modified from Zend framework)

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ index.php?url=$1 [QSA,NC,L]

1 Comment

Tried this. Same result :-(. THANK YOU.
1

I encountered the same thing, in my case the error was produced when I had a help.php file in the same directory. Don't know exactly why this happens...

1 Comment

This could happen if MultiViews is enabled, since this will cause /help to be internally rewritten to /help.php (if help.php exists as a physical file in that directory) before mod_rewrite gets to rewrite the request. In which case, you can disable MultiViews in per-directory .htaccess: Options -MultiViews.
0

You need to add:

RewriteBase /MyMVCProject

to your .htaccess file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.