当错误的网址时,重定向到404找不到

时间:2018-01-06 07:47:51

标签: php apache .htaccess redirect mod-rewrite

我有这样的链接

http://www.piratefiles.org/dorama/201214213/chase

我希望当有人更改原始网址时,例如像这样

http://www.piratefiles.org/dorama/201214213/chasegasdfghasfdhga

然后会重定向到404找不到

你可以尝试一下。那是我的网。

我的完整.htaccess代码

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

        RewriteCond %{HTTP_HOST} !^www\. [NC]
        RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
        RewriteRule ^([A-Za-z]+)/([0-9]+)/([\w-]+)/?$    view.php?cat=$1&idp=$2&post=$3&%{QUERY_STRING}   [NC,L]
        RewriteRule ^category/([\w-]+)/?$ category.php?cat=$1&%{QUERY_STRING}   [NC,L]

    # To externally redirect /dir/abc.php to /dir/abc
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC]
    RewriteRule ^ /%1 [R=301,L,NE]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
        RewriteRule ^(.+?)/?$ $1.php [QSA,NC,L]
</IfModule>

ErrorDocument 404 http://www.piratefiles.org/404.php

1 个答案:

答案 0 :(得分:0)

<强> 404.php

<?php
  header("HTTP/1.0 404 Not Found");
?>
<html>
  <head>
    <title>404 Error - Page Not Found</title>
  </head>
  <body>Your design</body>
</html>

<强>的.htaccess

ErrorDocument 404 /404.php