5

i'm trying to remove index.php form an URL:

this works

http://server/bw/index.php/test

this doesn't work

http://server/bw/test

i try to change .htaccess and watching on web i see that it should be like this:

RewriteEngine On
RewriteBase /bw/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

i try editing it in this way:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

or in this way:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /bw/index.php [QSA,L]

or in this way:

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

But when i try to access to http://server/bw/test it says me:

Not Found

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

Apache/2.2.15 (CentOS) Server at server Port 80

I check that inside my httpd.conf LoadModule rewrite_module modules/mod_rewrite.so is enable.. i don't know what to do now..

how can i solve? please help me!

3 Answers 3

6

Try this, which used e.g. in WordPress

RewriteRule . index.php [L]

or this, which is used by e.g. Lavavel PHP Framework

RewriteRule ^(.*)$ index.php/$1 [L]

You might also consider adding

RewriteCond %{REQUEST_FILENAME} !-d

before the RewriteRule to also exclude existing directories, not only existing files. But that's up to you.

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

7 Comments

nothing to do.. it doesn't works.. with both first and second rules
If you put these lines into a .htaccess file you should check if you have the directive AllowOverride set to All or FileInfo in your httpd.conf or the VirtualHost config because mod_rewrite needs this (see Apache documentation)
i tried to set AllowOverride to All inside httpd.conf but when i try to go to the url without index.php it loads the index.php of the directory that is over the directory that contains the index.php of slim framework
btw. if you add the !-d RewriteCond you have to put it between RewriteCond !-f and the RewriteRule because they are only applied to RewriteRule immediately following.
then maybe you have another .htaccess file somewhere up the directory tree, most likely in the parent directory itself.
|
1

In my case I updated AllowOverride All , then run sudo a2enmod rewrite to avoid Internal 500 error then restart Apache service apache2 restart

Comments

0

For me, I got things to work using this line from Dehalion's answer:

RewriteRule . index.php [L]

So the index.php (or any xyz.php) file is not seen in the request url

http://localhost/demo1/mycompany/hello/Jim

With the following caveats:

  1. You have this route defined:

    $app->get('/mycompany/hello/:name', doHello );

  2. The root element (for the route /mycompany/..) is also the name of the file.
    That is, the route exists in a file called "mycompany.php"

Yes, it's a bit of a hack ... but since I find apache config confusing/intimidating :) ... I figure this solution is stable enough to satisfy the requirements.

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.