How to Remove index.php from URL in PHP

杀马特。学长 韩版系。学妹 提交于 2019-12-11 02:59:58

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/7934150/how-to-remove-index-php-from-url-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!