阿帕奇的.htaccess:我如何重定向文件是不是没有发送404头发现了什么?重定向、发现了、阿帕奇、文件

2023-09-02 11:25:58 作者:叫自己放手

我的网站需要一个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

     在 - D'(就是目录)将TestString视为一个路径名并测试   它存在且是一个目录。   在' - F'(是常规文件)将TestString视为一个路径名并测试   它的存在,是一个普通文件。   在' - S'(与大小的常规文件)将TestString视为一个路径名   并测试它是否存在,是一个   大小大于常规文件   零。   在' - L'(是符号连接)将TestString视为一个路径名并测试   它的存在,是一个符号链接。   在' - F'(是现有对子请求文件)检查TestString是否一个   有效的文件,并通过所有可访问   服务器的当前配置的访问   控制了这条道路。它使用一个   内部子请求来确定   检查,所以请谨慎使用,因为它   降低服务器的性能!   在' - U'(是现有对子请求的URL)检查TestString是否一个   有效的URL,并通过所有可访问   服务器的当前配置的访问   控制了这条道路。它使用一个   内部子请求来确定   检查,所以请谨慎使用,因为它   降低服务器的性能!   

详细信息:http://httpd.apache.org/docs/current/mod/mod_rewrite.html

编辑:也请注意这个帖子: mod_rewrite的与godaddy

u 盘某个文件夹里面的东西突然都不见了 求大神指点

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

'-d' (is directory) Treats the TestString as a pathname and tests if it exists and is a directory. '-f' (is regular file) Treats the TestString as a pathname and tests if it exists and is a regular file. '-s' (is regular file with size) Treats the TestString as a pathname and tests if it exists and is a regular file with size greater than zero. '-l' (is symbolic link) Treats the TestString as a pathname and tests if it exists and is a symbolic link. '-F' (is existing file via subrequest) Checks if TestString is a valid file and accessible via all the server's currently-configured access controls for that path. This uses an internal subrequest to determine the check, so use it with care because it decreases your servers performance! '-U' (is existing URL via subrequest) Checks if TestString is a valid URL and accessible via all the server's currently-configured access controls for that path. This uses an internal subrequest to determine the check, so use it with care because it decreases your server's performance!

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

Edit: please also notice this post: Mod_rewrite with godaddy