1

I'm currently writing a PHP application, and I have always used frameworks and always worked in larger projects, but for this particular project I am doing neither. I've hit an issue where if I go to:

http://localhost/project

It runs the index.php file fine, but if I wanted to go to

http://localhost/project/test

I'd still want it to run the index.php file, and work out what to do with the 'test' part from there. Instead I'm getting a 404. How do I go about this?

I'm using Apache as my server, is it something I need to change in the .htaccess file? I'm pretty new to editing that file and have found most tutorials haven't said how to do this, but it seems like a pretty integral thing

edit:

This is what my htaccess currently looks like

Options +FollowSymLinks
IndexIgnore */*
# Turn on the RewriteEngine
RewriteEngine On
#  Rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
2
  • 2
    post your .htaccess file contents too Commented May 10, 2014 at 18:46
  • No worries, I've edited the original post Commented May 10, 2014 at 18:51

1 Answer 1

1

Try to change your .htaccess file into :

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)(.*)/?$ index.php

as initial solution to check if it works

Sign up to request clarification or add additional context in comments.

5 Comments

Progress! This threw a 500 error instead of a 404. Doesn't seem to be hitting my index.php though
So you should check your httpd.conf if mod_rewrite is enabled
The online line I could find in the conf file was: LoadModule rewrite_module modules/mod_rewrite.so which was commented out. So I uncommented it and restart apache but it still didn't work. I saw something online about running a2enmod rewrite in the terminal, but it didn't work. It's worth mentioning I'm running on Windows not Unix
Your comment above is possible not complete. In your httpd.cond you should have line LoadModule rewrite_module modules/mod_rewrite.so without # as first character and if you change it you need to restart Apache server
Okay I got it, I also had to set Options and AllowOverride in the <Directory> tags to All. Thanks a lot for the help!

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.