2016-08-05 24 views
0

我怎麼可以重寫URL所以不是這樣看:如何使用URL重寫一個htaccess文件

website.com/index.php/acars

它看起來像這樣:

website.com/index.php?p=acars

,也許像THI S:

website.com/acars

+0

請告訴我們你已經嘗試和你卡住的地方。 [google搜索](https://www.google.com/search?q=htaccess+url+rewrite)可能是一個很好的來源提示。 – showdev

回答

0

這裏是一個例子,我在Symfony2的項目中使用(我認爲這是默認的symfony htaccess的):

DirectoryIndex index.php 

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ 
    RewriteRule ^(.*) - [E=BASE:%1] 

    RewriteCond %{ENV:REDIRECT_STATUS} ^$ 
    RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L] 

    RewriteCond %{REQUEST_FILENAME} -f 
    RewriteRule .? - [L] 

    RewriteRule .? %{ENV:BASE}/index.php [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    <IfModule mod_alias.c> 
    RedirectMatch 302 ^/$ /index.php/ 
    </IfModule> 
</IfModule> 

所以每一個要求如website.com/acars將被處理像website.com/index.php/acars

+0

它沒有工作。它仍然顯示index.php頁面 –