.htacces - 将索引.php重定向到不可见的索引.php


.htacces - Redirect index.php to non-visible index.php

我想将旧页面(如"index.php/sdasdasd/sdasda/")重定向到他们的新内容。我正在使用PHP来做到这一点,因为数据存储在MySQL中。问题是,当URL以"index.php"开头时,它不会重定向到正确的页面。在后台,它应该调用:"index.php?url=index.php/sdasdasd/sdasda/"。如何在 .htaccess 中解决此问题?

RewriteEngine on
RewriteCond %{REQUEST_URI} !(/$|'.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
RewriteRule ^(.*/)?'.svn/ - [F,L]
RewriteRule '.(gif|jpg|png|css|flv|js|swf|php)$ - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+'.php)$ index.php?url=$1 [QSA,L]
RewriteCond %{REQUEST_URI} !('.)
RewriteCond %{REQUEST_URI} !('.)
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} .*
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

如果对此代码有任何其他改进,欢迎您提出更改建议。

如何在 .htaccess 中解决此问题?

您有一个重复的条件:

RewriteCond %{REQUEST_URI} !('.)
RewriteCond %{REQUEST_URI} !('.)

您可以删除其中一个。

但是为了将请求重定向到 /index.php/something ,您需要在下面添加以下内容 RewriteEngine on

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