Mod_Rewrite删除/index.php/

时间:2014-03-27 09:24:18

标签: apache .htaccess mod-rewrite

我有旧的网址,想通过.htaccess删除/index.php/:

所以旧网址是:

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

在.htaccess中重写进入

 www.mysite.com/onesite.html

我该怎么做?

感谢您的帮助

4 个答案:

答案 0 :(得分: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]

答案 1 :(得分:0)

将以下代码添加到您的htaccess将允许此

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

当您确定重定向正在运行时,将302更改为301

答案 2 :(得分:0)

试试这个:

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

答案 3 :(得分: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>