【问题标题】:redirect to 404 not found when wrong url错误 url 时找不到重定向到 404
【发布时间】:2018-01-06 07:47:50
【问题描述】:

我有这样的链接

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

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

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

然后会重定向到 404 not found

你可以试试。那是我的网络。

我的完整 .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

【问题讨论】:

  • 您可以在您的 php 代码中执行此操作。如果您使用 MVC 结构,您可以检查是否定义了操作。

标签: php apache .htaccess redirect mod-rewrite


【解决方案1】:

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 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-12
    • 1970-01-01
    • 1970-01-01
    • 2011-11-15
    • 1970-01-01
    • 1970-01-01
    • 2011-07-02
    • 1970-01-01
    相关资源
    最近更新 更多