Fatih Donmez
Fatih Donmez

Reputation: 4347

How to Remove index.php from URL in PHP

I want to remove index.php from url but so far i couldn't succeed it. I'm using Wamp server on my local and Apache on remote server.. In local root directory, my project files are located in a subfolder like

www/project/index.php

I can access web pages like

localhost/project/index.php/home

localhost/project/index.php/messages/?mId=3

I just want to access it like

localhost/project/home
localhost/project/messages/?mId=3

I already tried some .htaccess rewrite rule but couldnt make it.

Upvotes: 2

Views: 2143

Answers (2)

Eugene
Eugene

Reputation: 4389

Here's how you need to organize:

<ifModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php/$1 [NC,QSA,L]
</ifModule>

And then you will have everything as you need.

Upvotes: 2

Martin Samson
Martin Samson

Reputation: 4090

You will want to use url rewriting with a .htaccess file:

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

Put a .htaccess with this content in each subfolder.

Upvotes: 1

Related Questions