从 http://domain.com/index.php?controller/action 中删除“索引.php?


Removing "index.php?" from http://domain.com/index.php?controller/action

我在 PHP MVC 中创建了一个应用程序,http 请求是这样的domain.com/index.php?controller/action,我想移除索引.php?,最终到达网址看起来像 http://domain.com/controller/action。任何帮助将不胜感激

目前我的.htaccess文件如下所示

RewriteEngine On
RewriteBase /
<IfModule mod_rewrite.c>
# Removes index.php from ExpressionEngine URLs
RewriteCond $1 !'.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

它只会删除索引.php并且 URL 变得 http://domain.com/?controller/action,我希望"?"从 URL 中关闭。

使用mod_rewire模块来完成工作。您问的是SEO友好的URL。如果你搜索一下搜索,你会发现很多例子。

把它放在你的根.htaccess文件中。

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