2014-03-27 54 views
0

我有舊的網址,並希望通過的.htaccess刪除/index.php/:ModRewrite刪除/index.php/

所以舊的URL是:

www.mysite.com/index.php/onesite.html 

重寫在.htaccess到

www.mysite.com/onesite.html 

我怎麼能這樣做?

THX對您有所幫助

回答

0

您可以使用這條規則在您DOCUMENT_ROOT/.htaccess文件:

RewriteEngine On 

RewriteCond %{THE_REQUEST} /index\.php [NC] 
RewriteRule ^index\.php(/.*)?$ $1 [L,R=301,NC,NE] 

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

謝謝你,但它不工作 – cuSoon2013

+0

什麼這個.htaccess的位置和你嘗試過什麼URL? – anubhava

0

添加以下代碼到你的htaccess將允許該

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^index.php/(.*)$ www.mysite.com/$1 [R=302,L] 

更改302301當您確定重定向正在工作時

0

試試這個:

RewriteRule ^index.php/(.*?)$ http://%{HTTP_HOST}/$1 [R=301,L] 
+0

添加一些解釋會很有用。 –

0

就在你的.htaccess

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

添加此如果你的網站是在子目錄下,那麼

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /shop/ 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /shop/index.php [L] 
</IfModule>