.htaccess url-rewrite if file not exists

后端 未结 3 2109
耶瑟儿~
耶瑟儿~ 2020-12-03 02:45

I must do a little trick for a site! The idea is:

  • if a file for a required url exists then I go to that url, doing nothing more;
  • if a file for a requi
相关标签:
3条回答
  • 2020-12-03 03:15
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^.*$ /default.php [L]
    
    0 讨论(0)
  • 2020-12-03 03:25

    It is not mentioned here but FallbackResource is the new recommended way of handling not-found (404) URLs. Example:

    FallbackResource /not-404.php 
    

    From Apache manual:

    Use this to set a handler for any URL that doesn't map to anything in your filesystem, and would otherwise return HTTP 404 (Not Found).

    0 讨论(0)
  • 2020-12-03 03:31

    Implement a 404 error rule. Doesn't require mod_rewrite:

    ErrorDocument 404 /default.php
    
    0 讨论(0)
提交回复
热议问题