2017-09-12 22 views
1

我有一个像http://example.com/index.php/fruit/1a2b3c获取URI PARAMS没有的index.php

我想要得到我已经写了代码的URI的一个网址。

现在我想删除从可见网址的index.php文件,甚至当URL是http://example.com/fruit/1a2b3c它应该工作,它应该仍然指向到index.php

我的Apache2上使用PHP 7

+0

的[从由htaccess的URL中删除的index.php](https://stackoverflow.com/questions/20673235/remove-index-php-from-url-by-htaccess)的 – Ali

+0

可能的复制可能的复制[htaccess从url删除index.php](https://stackoverflow.com/questions/4365129/htaccess-remove-index-php-from-url) –

+0

[参考:mod \ _rewrite,URL重写和“漂亮链接“解释](https://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) –

回答

1

将以下代码添加到.htaccess文件中。

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

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

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC] 
RewriteRule^%1 [R=301,L] 
+0

嘿非常感谢您的答案,它确实解决了我的问题,你能否也请逐行解释它是如何工作的?我发现很难理解它是什么以及它是如何做到的? – zegulas

0

.htaccess文件改变,

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

希望这会工作。