我的网站需要一个htaccess文件,它将在找不到页面将用户重定向到index.php文件。不过,我不希望阿帕奇发送404头的文件。
我问这个问题前面: 的Apache的.htaccess重定向
命令的ErrorDocument的index.php产生,我想,除了它发送一个404头与页面的确切疗效。我能做什么?我应该覆盖404头用PHP?
谢谢你们。
解决方案添加到您的的.htaccess
文件:
RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME -s [OR]
的RewriteCond%{} REQUEST_FILENAME -l [OR]
的RewriteCond%{} REQUEST_FILENAME -d
。重写规则^ * $ - [NC,L]
重写规则^ * $的index.php [NC,L]
使重写 检查请求的文件存在,作为一个regualar文件大小(不为空) 检查请求的文件链接 检查请求的文件是目录 如果的previous 3语句之一,则显示该文件 否则转到到index.php
如果重定向到index.php发生的美国可以通过使用获得请求的URI $ _ SERVER [REQUEST_URI]
在的index.php
详细信息:http://httpd.apache.org/docs/current/mod/mod_rewrite.html
编辑:也请注意这个帖子: mod_rewrite的与godaddy
My website needs a htaccess file that will redirect a user to index.php when a page is not found. However, I do not want Apache to send a 404 header with the document.
I asked this question earlier: Apache .htaccess redirect
The command "ErrorDocument /index.php" produces the exact effect that I want, except that it sends a 404 header with the page. What can I do? Should I overwrite the 404 header with PHP?
Thanks guys.
解决方案Add this to your .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]
enable rewrite check if requested file exists as a regualar file with size (not empty) check if requested file is link check if requested file is a directory if one of the previous 3 statements is true show that file otherwise go to index.php
If the redirect to index.php happens u can get the requested uri by using $_SERVER["REQUEST_URI"]
inside index.php
More information: http://httpd.apache.org/docs/current/mod/mod_rewrite.html
Edit: please also notice this post: Mod_rewrite with godaddy