开发者

.htaccess redirect problem

开发者 https://www.devze.com 2022-12-14 20:35 出处:网络
i have following开发者_StackOverflow of 404 page.... RewriteCond %{REQUEST_FILENAME} !-f RewriteRule (.+)$ ?file=$1 [L]

i have following开发者_StackOverflow of 404 page....

RewriteCond %{REQUEST_FILENAME} !-f RewriteRule (.+)$ ?file=$1 [L]

but it is showing this page to all directories and page event the root directory


Make sure that the rewrite engine is turned on in .htaccess or your vhost declaration. Also, you need to check if directories or symlinks exist for the request. Here's an updated example:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f   
RewriteCond %{REQUEST_FILENAME} !-d   
RewriteCond %{REQUEST_FILENAME} !-l   
RewriteRule (.+)$ /404.php?page=$1 [L] 

Apache also has a document handler for 404 / file-not-found responses. You can access the file requested via the REQUEST_URI header. Here's an example with the corresponding Apache rules and PHP 404 error handler file:

.htaccess:

ErrorDocument 404 /404.php

404.php:

<?php
 echo "Tried to access: {$_SERVER['REQUEST_URI']}";
?>

I prefer the ErrorDocument handler, as Apache will still log the 404 response code, which is useful for generating analytics for missing page / broken links.

0

精彩评论

暂无评论...
验证码 换一张
取 消