2

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.

2 Answers 2

2

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.

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

Comments

1

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.

3 Comments

Thanks Martin, it's working.. But one more question, I can still type url with index.php and not removing index.php. It's working when I type localhost/project/home but when i type /localhost/project/index.php/home it's still in there?
Also after .htaccess change $_SERVER['PATH_INFO'] is just empty.. I was using it in index.php to calculate controller name fro url.
yeah, with this rewrite conditions, everything will be accessible in $_GET['url'] instead of PATH_INFO

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.