我有什么-类似的URL
http://example.com/index.php/anywords/anywords/anyname.php
或
http://example.com/index.php/anywords/anywords/
或
http://example.com/index.php/
我想要什么-重定向到
http://example.com/index.php
我当前的htaccess文件
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /(.*)/$
RewriteRule ^ /%1 [R=302,L]
</IfModule>
感谢
用于匹配任何单词的通用解决方案: 请尝试以下操作。我在这里提到了临时重定向,如果你不想在浏览器级别重定向,你可以删除它。
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/index.php/([w-]+/){1,}/[w]+.php/? [NC,OR]
RewriteCond %{REQUEST_URI} ^/index.php/([w-]+/){1,}/? [NC,OR]
RewriteCond %{REQUEST_URI} ^index.php/?$ [NC]
RewriteRule ^(.*)$ /index.php [R=302,NC,L]
对于特定的单词:你能试一下吗。
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/index.php/anywords/anywords/anyname.php/? [NC,OR]
RewriteCond %{REQUEST_URI} ^/index.php/anywords/anywords/?$ [NC,OR]
RewriteCond %{REQUEST_URI} ^index.php/?$ [NC]
RewriteRule ^(.*)$ /index.php [R=302,NC,L]