如何从 PHP 中的 URL 中删除 index.php
问题描述:
我想从 url 中删除 index.php 但到目前为止我无法成功.我在本地服务器上使用 Wamp 服务器,在远程服务器上使用 Apache..在本地根目录中,我的项目文件位于像
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
我可以访问像
localhost/project/index.php/home
localhost/project/index.php/messages/?mId=3
我只想像访问它
localhost/project/home
localhost/project/messages/?mId=3
我已经尝试了一些 .htaccess 重写规则,但无法实现.
I already tried some .htaccess rewrite rule but couldnt make it.
答
以下是您需要的组织方式:
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.