由于.htaccess文件导致404错误

时间:2015-03-21 08:07:30

标签: php html .htaccess http-status-code-404 google-webmaster-tools

我有一个网站。在这个网站上,根据我的谷歌网站管理员,我有一些404文件找不到错误,尽管所有文件都存在。它们如下:

http://firstcovers.net/http//firstcovers.net/
http://firstcovers.net/category/1/http//firstcovers.net/
http://firstcovers.net/category/8/4/http//firstcovers.net/
http://firstcovers.net/category/17/2/http//firstcovers.net/
http://firstcovers.net/category/20/2/http//firstcovers.net/
http://firstcovers.net/facebook-cover/1317/privacy.php
http://firstcovers.net/facebook-cover/1317/terms.php
http://firstcovers.net/facebook-cover/1286/privacy.php
http://firstcovers.net/facebook-cover/338/terms.php

.htaccess文件的结构如下:

DirectoryIndex index.html.var index.htm index.html index.shtml index.xhtml index.wml index.perl index.pl index.plx index.ppl index.cgi index.jsp index.js index.jp index.php4 index.php3 index.php index.phtml default.htm default.html home.htm index.php5 Default.html Default.htm home.html
# Use PHP5 Single php.ini as default
#AddHandler fcgid-script .php
RewriteEngine On


RewriteRule ^latest.html /index.php?latest=y [L]
RewriteRule ^random.html /index.php?random=y [L]
RewriteRule ^showall.html /index.php?showall=y [L]
RewriteRule ^about.html /about.php [L]
RewriteRule ^userupload.html /userupload.php [L]
RewriteRule ^get-timeline.html /how.php [L]

RewriteRule ^facebook-cover-([0-9]+).html /detailpage.php?cp=$1 [L]
RewriteRule ^facebook-cover/([0-9]+)/([^/]*).html /detailpage.php?cp=$1 [L]
RewriteRule ^preview/([0-9]+)/([^/]*).html /detailpage.php?preview=y&cp=$1 [L]
RewriteRule ^category/([^/]*)/([^/]*).html /index.php?cat=$1 [L]
RewriteRule ^category/([^/]*)/([^/]*)/([^/]*).html /index.php?cat=$1&page=$2 [L]
RewriteRule ^cover-([0-9]+).html  /image.php?picID=$1 [L]
RewriteBase /
RewriteRule ^css/(.*\.css) /combine.php?type=css&files=$1
RewriteRule ^javascript/(.*\.js) /combine.php?type=javascript&files=$1

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
<FilesMatch "\\.(js|css|html|htm|php|xml)$">
# compress text, HTML, JavaScript, CSS, and XML
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
SetOutputFilter DEFLATE
</FilesMatch>

Header set Expires "Thu, 15 Apr 2030 20:00:00 GMT"
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_REFERER}     !^$
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} .(gif|jpe?g?|png)$ [NC]
RewriteCond %{HTTP_REFERER}     !^https?://([^.]+.)?firstcovers. [NC]
RewriteRule .(gif|jpe?g?|png)$ - [F,NC,L]
</ifModule>
RewriteCond %{HTTP_REFERER} !^http://www.google.com/reader/view/.*$ [NC]
# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On 
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>

FileETag MTime Size

我尽力改变.htaccess文件的正则表达式。但我仍然犯了一些错误。我无法追查这个错误。

我请求本网站的会员帮助我。

**提前致谢。

你的朋友。

V K Saw。**

2 个答案:

答案 0 :(得分:3)

以下404s

http://firstcovers.net/facebook-cover/1317/privacy.php
http://firstcovers.net/facebook-cover/1317/terms.php
http://firstcovers.net/facebook-cover/1286/privacy.php
http://firstcovers.net/facebook-cover/338/terms.php

修改您的facebook-cover规则以匹配.php网址。

RewriteRule ^facebook-cover/([0-9]+)/([^/]*)\.(php|html)$ /detailpage.php?cp=$1 [L]

404链接的其余部分

http://firstcovers.net/http//firstcovers.net/
http://firstcovers.net/category/1/http//firstcovers.net/
http://firstcovers.net/category/8/4/http//firstcovers.net/
http://firstcovers.net/category/17/2/http//firstcovers.net/
http://firstcovers.net/category/20/2/http//firstcovers.net/

不是由.htaccess文件生成的。检查您的PHP代码是否生成了错误的URL。在某处,它最后附加http//firstcovers.net/。您正在使用一些自定义标记(例如<g:plusone>),这也可能是一个此类标记库中的错误。

答案 1 :(得分:1)

这些是您提供的404错误的网址

http://firstcovers.net/http//firstcovers.net/
http://firstcovers.net/category/1/http//firstcovers.net/
http://firstcovers.net/category/8/4/http//firstcovers.net/
http://firstcovers.net/category/17/2/http//firstcovers.net/
http://firstcovers.net/category/20/2/http//firstcovers.net/
http://firstcovers.net/facebook-cover/1317/privacy.php
http://firstcovers.net/facebook-cover/1317/terms.php
http://firstcovers.net/facebook-cover/1286/privacy.php
http://firstcovers.net/facebook-cover/338/terms.php

提供的网址存在两组问题。让我们逐一解决问题。第一组网址是:

http://firstcovers.net/facebook-cover/1317/privacy.php
http://firstcovers.net/facebook-cover/1317/terms.php
http://firstcovers.net/facebook-cover/1286/privacy.php
http://firstcovers.net/facebook-cover/338/terms.php

我访问了您的网页,发现代码为:

<a class="uibutton" href="#" onClick="newInvite(); return false;">Invite</a>
<a class="uibutton icon secure" onclick="privacy(); return false;">Privacy</a>
<a class="uibutton" onclick="terms(); return false;">Terms</a>

您必须更改代码以解决问题,如下所示:

<a class="uibutton" href="#" onClick="newInvite(); return false;">Invite</a>
<a class="uibutton icon secure" href="#"  onclick="privacy(); return false;">Privacy</a>
<a class="uibutton" href="#" onclick="terms(); return false;">Terms</a>

在您的代码中href="#"缺少导致第一组网址出现问题的代码。在您的网址中,Invite不包含在404错误中,因此它将解决第一组网址问题。

第二组网址:

http://firstcovers.net/http//firstcovers.net/
http://firstcovers.net/category/1/http//firstcovers.net/
http://firstcovers.net/category/8/4/http//firstcovers.net/
http://firstcovers.net/category/17/2/http//firstcovers.net/
http://firstcovers.net/category/20/2/http//firstcovers.net/

首先要提到的是,您的网站是动态的,您通过第三方工具(如python脚本)生成站点地图,或者可能是其他的,这反过来又访问了apache访问日志。因为,url是唯一的,url是在sitemap中添加的,并且没有url因此404错误。

您的问题有两种解决方案:

  1. 删除不需要的网址,例如这些会导致网站地图出现问题。为此,您需要查看/阅读第三方工具文档。

  2. 无论您在网址中再次显示自己的网站名称,都可以将其重定向到主页网址,因为您具有正则表达式的知识,因此对您来说不会有任何问题。