我想将页面重定向到index.php。当我点击某个链接时,它会重定向到http://example.com/article.php
之类的尚未存在的内容。由于它不存在,我想重定向到index.php。
我尝试过类似的事情:
RewriteRule ^article.\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [R=301]
此代码重定向到index.php,但网站上的每个链接都不会重定向到article.php
答案 0 :(得分:1)
您可以改用此规则:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?:^|/)article\.php$ /index.php? [L,NC,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
确保仅当index.php
不是系统中的有效文件时才会发生重定向。