.htaccess在空时重定向,在修改时抛出403

时间:2014-04-24 20:44:45

标签: .htaccess caching redirect http-status-code-403

我的.htaccess文件存在问题。在我进入之前,请注意我无法访问实际的Apache服务器,只能访问FTP(意味着我无法重启)。

几个月前我在这个网站上工作过,而.htaccess文件中的重定向规则如下所示:

######################################################## error document handling
ErrorDocument 301 /index.php?htfail=301
ErrorDocument 302 /index.php?htfail=302
ErrorDocument 400 /index.php?htfail=400
ErrorDocument 401 /index.php?htfail=401
ErrorDocument 402 /index.php?htfail=402
ErrorDocument 403 /index.php?htfail=403
ErrorDocument 404 /index.php?htfail=404
ErrorDocument 405 /index.php?htfail=405
ErrorDocument 408 /index.php?htfail=408
ErrorDocument 415 /index.php?htfail=415
ErrorDocument 500 /index.php?htfail=500
ErrorDocument 501 /index.php?htfail=501
ErrorDocument 502 /index.php?htfail=502
ErrorDocument 503 /index.php?htfail=503
ErrorDocument 504 /index.php?htfail=504
ErrorDocument 505 /index.php?htfail=505

#################################################################### mod_rewrite
RewriteEngine On
RewriteBase /

RewriteRule ^index(.*)$ index.php [L]
RewriteRule ^informationen(.*)$ index.php?site=informationen [L]
RewriteRule ^mitmachen(.*)$ index.php?site=mitmachen [L]
RewriteRule ^teilnahmebedingungen(.*)$ index.php?site=teilnahmebedingungen [L]
RewriteRule ^impressum(.*)$ index.php?site=impressum [L]
RewriteRule ^clubbing(.*)$ index.php?site=clubbing [L]
RewriteRule ^archiv/(.*)/$ index.php?site=archiv&idea=$1 [L]
RewriteRule ^archiv(.*)$ index.php?site=archiv [L]
RewriteRule ^feedback/(.*)/$ index.php?site=feedback&idea=$1 [L]
RewriteRule ^feedback(.*)$ index.php?site=feedback [L]

现在我回来添加了一些新的重定向,令我惊讶的是,.htaccess文件以某种方式发生了变化(见下文 - 确定不是我的意思),但重定向仍然有效。我认为这可能是因为浏览器缓存了重定向,但如果我以隐身模式打开网站并清空缓存,它也可以工作。如果我重命名.htaccess文件,或删除它,请将其设为空 - 仍然有效!

######################################################## error document handling
#################################################################### mod_rewrite

正如我所说,我想添加一些新的重定向。如果我将文件的内容更改为除空/注释之外的任何其他内容(比如在那里添加一些新的RewriteRules),服务器会向我抛出403:

Forbidden

You don't have permission to access / on this server.

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

这就是我修改.htaccess的方法。我不能使用这个新代码,或者第一个代码块中的原始代码 - 我得到403这两个代码。

######################################################## error document handling
ErrorDocument 301 /index.php?htfail=301
ErrorDocument 302 /index.php?htfail=302
ErrorDocument 400 /index.php?htfail=400
ErrorDocument 401 /index.php?htfail=401
ErrorDocument 402 /index.php?htfail=402
ErrorDocument 403 /index.php?htfail=403
ErrorDocument 404 /index.php?htfail=404
ErrorDocument 405 /index.php?htfail=405
ErrorDocument 408 /index.php?htfail=408
ErrorDocument 415 /index.php?htfail=415
ErrorDocument 500 /index.php?htfail=500
ErrorDocument 501 /index.php?htfail=501
ErrorDocument 502 /index.php?htfail=502
ErrorDocument 503 /index.php?htfail=503
ErrorDocument 504 /index.php?htfail=504
ErrorDocument 505 /index.php?htfail=505

#################################################################### mod_rewrite
RewriteEngine On
RewriteBase /

RewriteRule ^index(.*)$ index.php [L]
RewriteRule ^informationen(.*)$ index.php?site=informationen [L]
RewriteRule ^mitmachen(.*)$ index.php?site=mitmachen [L]
RewriteRule ^teilnahmebedingungen(.*)$ index.php?site=teilnahmebedingungen [L]
RewriteRule ^impressum(.*)$ index.php?site=impressum [L]
RewriteRule ^clubbing(.*)$ index.php?site=clubbing [L]
RewriteRule ^archiv/(20\d{2})/(.*)/?$ index.php?site=archiv$1&idea=$2 [L]
RewriteRule ^archiv/(20\d{2})/?$ index.php?site=archiv$1 [L]
RewriteRule ^archiv(.*)$ index.php?site=archiv2014 [L]
RewriteRule ^feedback/(.*)/$ index.php?site=feedback&idea=$1 [L]
RewriteRule ^feedback(.*)$ index.php?site=feedback [L]

我一直在抨击我的头几个小时,也许有更多Apache经验的人可以帮我解决这个问题?

1 个答案:

答案 0 :(得分:0)

尝试使用Mod Rewrite或联系您的主机为您设置。 http://httpd.apache.org/docs/current/mod/mod_rewrite.html