Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
694 views
in Technique[技术] by (71.8m points)

.htaccess - How to remove index.php from slim framework URL

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...