【发布时间】:2014-03-27 09:24:17
【问题描述】:
我有旧网址并想通过 .htaccess 删除 /index.php/:
所以旧网址是:
www.mysite.com/index.php/onesite.html
将 .htaccess 中的改写成
www.mysite.com/onesite.html
我该怎么做?
感谢您的帮助
【问题讨论】:
标签: apache .htaccess mod-rewrite
我有旧网址并想通过 .htaccess 删除 /index.php/:
所以旧网址是:
www.mysite.com/index.php/onesite.html
将 .htaccess 中的改写成
www.mysite.com/onesite.html
我该怎么做?
感谢您的帮助
【问题讨论】:
标签: apache .htaccess mod-rewrite
将以下代码添加到您的 htaccess 将允许这样做
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^index.php/(.*)$ www.mysite.com/$1 [R=302,L]
当您确定重定向正常工作时,将 302 更改为 301
【讨论】:
试试这个:
RewriteRule ^index.php/(.*?)$ http://%{HTTP_HOST}/$1 [R=301,L]
【讨论】:
只需将其添加到您的 .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>
【讨论】:
您可以在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]
【讨论】: