doufeikuang7724 2017-10-02 14:27
浏览 69
已采纳

htaccess:2个不同的404错误文件(或内容)

I am using a .htaccess file to catch ErrorDocument. Now, I have :

ErrorDocument 404 /errors/error404.php

It works great, but now, I want another error 404 file (or another content for this file), if the previous url contained "eu".

ErrorDocument 404 /errors/error404.php
<!-- If URL contains "eu", do : -->
ErrorDocument 404 /errors/eu_error404.php

Is this possible ? Or can I catch the URL where I came to execute differents include with PHP ?

I would like to avoid $_SESSION..
I saw things like : $_SERVER['HTTP_REFERER']

Can someone explains me :) ?

  • 写回答

3条回答 默认 最新

  • dt56449492 2017-10-02 16:25
    关注

    Save your code and try the following code :

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (eu)+
    #the line above will catch any request contains eu
    RewriteRule ^(.*)$ /errors/eu_error404.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !(eu)+
    #the line above will exclude any request contains eu
    RewriteRule ^(.*)$ /errors/error404.php
    

    Update

    If you wanna only the request that start with eu change the code as follow :

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^/eu
    #the line above will catch any request starts with eu
    RewriteRule ^(.*)$ /errors/eu_error404.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/eu
    #the line above will exclude any request starts with eu
    RewriteRule ^(.*)$ /errors/error404.php
    

    And regarding your question is that affect the SEO , it is not SEO issue but user experience issue , for example if you have old pages and users still requested and you redirect them for irrelevant page that will give them bad so the best way to handle it with alternative pages , regarding the search engines the 404 when it comes from any request will be on hold then removed after many request but more 404 is not good in some situation so , it depends in your expected error pages , are they already indexed before and it is better to redirect them for related pages or just wrong request and you wanna guide users to right way but believe the wrong request will not be more than correct in normal practice so it is not issue to redirect them to page that explain their mistake and guide them to correct page etc..

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效