我最近通过.htaccess设置了index.php重定向。这里的想法是否定当站点同时索引index.php和/(homapage)时出现的重复内容问题。
这是我原来的.htaccess
Options -Indexes
ErrorDocument 403 /customerrors/403.html
ErrorDocument 401 /customerrors/401.html
ErrorDocument 400 /customerrors/400.html
ErrorDocument 500 /customerrors/500.html
ErrorDocument 404 /customerrors/404.html
非常基本。
我使用此处列出的技术将index.php重定向到/.
http://www.askapache.com/htaccess/redirect-index-blog-root.html
它也很棒。一个问题是,它打破了404页面。
这是修改后的.htaccess,打破了404页面。
RewriteEngine On
RewriteBase /
DirectoryIndex index.php
RewriteCond %{http_host} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://example.com/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Options -Indexes
ErrorDocument 403 /customerrors/403.html
ErrorDocument 401 /customerrors/401.html
ErrorDocument 400 /customerrors/400.html
ErrorDocument 500 /customerrors/500.html
ErrorDocument 404 /customerrors/404.html
因此,如果用户输入或访问www.example.com/dafjkadbfda而不是提供404页面,则URL保持不变(在这种情况下是损坏的URL)并切断index.php页面。
这反过来又开启了另一种蠕虫病毒。所有这些破碎的页面都将作为重复内容和meta。
出现是否有另一种方法来编写将考虑404页面的.htacess重定向?这似乎就是这里的冲突。
提前致谢。
答案 0 :(得分:0)
.htaccess的这一部分是“打破”404:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
您可以通过从PHP脚本发送404错误来管理问题:
if ($not_a_valid_page){
header("$_SERVER[SERVER_PROTOCOL] 404 Not Found");
readfile("./customerrors/404.html");
die();
}