apache - How do I redirect a URL that isn't found without sending a 404 header? -


my website needs .htaccess file redirect user index.php when page not found. however, not want apache send 404 header document.

i asked question earlier: apache .htaccess 404 error redirect

the command "errordocument /index.php" produces exact effect want, except sends 404 header page. can do? should overwrite 404 header php?

add .htaccess file:

rewriteengine on rewritecond %{request_filename} -s [or] rewritecond %{request_filename} -l [or] rewritecond %{request_filename} -d rewriterule ^.*$ - [nc,l] rewriterule ^.*$ index.php [nc,l] 
  1. enable rewrite
  2. check if requested file exists regualar file size (not empty)
  3. check if requested file link
  4. check if requested file directory
  5. if 1 of previous 3 statements true show file
  6. otherwise go index.php

if redirect index.php happens u can requested uri using $_server["request_uri"] inside index.php

  • '-d' (is directory) treats teststring pathname , tests if exists , directory.
  • '-f' (is regular file) treats teststring pathname , tests if exists , regular file.
  • '-s' (is regular file size) treats teststring pathname , tests if exists , regular file size greater zero.
  • '-l' (is symbolic link) treats teststring pathname , tests if exists , symbolic link.
  • '-f' (is existing file via subrequest) checks if teststring valid file , accessible via server's currently-configured access controls path. uses internal subrequest determine check, use care because decreases servers performance!
  • '-u' (is existing url via subrequest) checks if teststring valid url , accessible via server's currently-configured access controls path. uses internal subrequest determine check, use care because decreases server's performance!

more information: http://httpd.apache.org/docs/current/mod/mod_rewrite.html

edit: please notice post: https://stackoverflow.com/questions/486505/mod-rewrite-with-godaddy


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -