ppp
ppp

Reputation: 2055

Apache rewrite - clean URLs in localhost

I have been trying for the past few hours to write clean URLs in my LAMP machine.

Apache's mod_rewrite is enabled, and I am trying to use an .htaccess file to pass the URL GET parameters to my index.php script which at the time is just a var_dump of _GET.

My current .htaccess is the following (although I've tried quite a few variations of it I found on other answers with no success)

RewriteEngine On

#Make sure it's not an actual file
RewriteCond %{REQUEST_FILENAME} !-f

#Make sure its not a directory
RewriteCond %{REQUEST_FILENAME} !-d 

#Rewrite the request to index.php
RewriteRule ^(.*)$ index.php?/get=$1 [L]

When I point my browser to localhost/my_project/test, all I get is a 404 error saying:

Not Found

The requested URL /my_project/test was not found on this server.

Apache/2.2.22 (Ubuntu) Server at localhost Port 80

Apparently I'm missing something obvious here, any help?

Upvotes: 3

Views: 4153

Answers (1)

anubhava
anubhava

Reputation: 785721

2 things to look for:

  1. Make sure .htaccess is enabled
  2. Make sure above code is in my_project directory.

Then add RewriteBase line as well:

RewriteEngine On
RewriteBase /my_project/

#Make sure it's not an actual file
RewriteCond %{REQUEST_FILENAME} !-f
#Make sure its not a directory
RewriteCond %{REQUEST_FILENAME} !-d 
#Rewrite the request to index.php
RewriteRule ^(.*)$ index.php?get=$1 [L]

Upvotes: 3

Related Questions