当前位置: 动力学知识库 > 问答 > 编程问答 >

caching - .htaccess redirects when empty, throws 403 when modified

问题描述:

I have a problem with my .htaccess file. Before I get into it, note that I don't have access to the actual Apache server, only FTP (meaning I can't restart it).

I worked on this site a couple months ago, and my redirection rules in the .htaccess file looked like this:

######################################################## 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]

Now I came back to add some new redirections, and to my surprise, the .htaccess file somehow changed (see below — sure as hell wasn't me), but the redirections still worked. I thought it might be because the browser cached the redirects, but it also works if I open the site in incognito mode, and empty the cache. If I rename the .htaccess file, or delete it, make it empty — still works!

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

#################################################################### mod_rewrite

As I said, I wanted to add some new redirects. If I change the file's content to anything else other than empty/comments (like adding some new RewriteRules in there), the server throws a 403 at me:

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.

This is how I modified the .htaccess. I can't use this new code, or the original one from the first codeblock – I get 403 for both of those.

######################################################## 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]

I've been bashing my head for a couple of hours on this, perhaps someone with more Apache experience can help me with this?

网友答案:

Try Mod Rewrite or contact your host to set it up for you. http://httpd.apache.org/docs/current/mod/mod_rewrite.html

分享给朋友:
您可能感兴趣的文章:
随机阅读: