此处将为大家介绍关于使用.htaccess的详细内容,并且为您解答有关ErrorDocument404+重写规则为某些文件types设置Web服务器句柄404错误的相关问题,此外,我们还将为您介绍关于
此处将为大家介绍关于使用.htaccess的详细内容,并且为您解答有关ErrorDocument 404 +重写规则为某些文件types设置Web服务器句柄404错误的相关问题,此外,我们还将为您介绍关于.htaccess通过PHP显示404,403,500,错误页面、.htaccess重写规则冲突、.htaccess重写规则的麻烦、.htaccess,将404错误重写到其他域的有用信息。
本文目录一览:- 使用.htaccess(ErrorDocument 404 +重写规则)为某些文件types设置Web服务器句柄404错误
- .htaccess通过PHP显示404,403,500,错误页面
- .htaccess重写规则冲突
- .htaccess重写规则的麻烦
- .htaccess,将404错误重写到其他域
使用.htaccess(ErrorDocument 404 +重写规则)为某些文件types设置Web服务器句柄404错误
这是我在这个伟大的社区的第一个问题(请告诉我,如果我做错了什么)。 在过去的5 – 6年里,我从你的答案中学到了很多东西,现在我有非常具体的问题,在互联网上找不到(这是可能的吗?)…
目标是设置自定义ErrorDocument 404,处理不存在select的静态文件,如: /notfound.jpg和子目录(对于任何目录):/ dir/notfound.jpg ,在wordpress下运行的网站启用漂亮的固定链接。 当一些select的静态文件丢失或连接不正确时,它将避免服务器的高负载!
我在.htaccess文件中使用W3 Totalcaching插件稍微修改过的代码:
ErrorDocument 404 /_code_404.html # BEGIN (modified) W3TC Skip 404 error handling by wordpress for static files <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_URI} !(robots.txt|sitemap.xml(.gz)?) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} .(css|js|bmp|gif|ico|jpg|jpeg|jpe|png|swf)$ [NC] RewriteRule .* - [L] </IfModule> # END (modified) W3TC Skip 404 error handling by wordpress for static files # BEGIN wordpress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index.PHP$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.PHP [L] </IfModule> # END wordpress
我试图用2个不同的服务器与Cpanel共享计划,都有wordpress与漂亮的固定链接,结果是一样的:
public_html中的.htaccess返回404页面
如何在.htaccessredirect后通过ajax请求保留POST数据?
laravel和wordpress在同一个域(子文件夹中的laravel)
.htaccess将子域redirect到域
htaccessredirect删除index.PHP
像http://img.zgserver.com/wordpress/notfound.jpg这样的请求正常工作
没有find像这个http://img.zgserver.com/wordpress/notfound.jpg子目录中的文件的工作。 在这种情况下,WP处理请求,并显示404页面,我想避免某些文件types,即静态文件,如:CSS,JS,JPG和一些…
任何答案和意见,欢迎,谢谢! 我可以尝试你可能有的任何build议(甚至未经testing)。
编辑1:彼此试图让它工作的说明(请参阅接受的答案+下面的注释):
看来你必须(或依赖于服务器configuration)设置自定义错误404页面,否则排除某些选定的文件types的重写将不起作用,并因此WP将处理请求! (似乎没有多less人注意到这一点,或者它可能与服务器configuration有关)
我意识到,因为我甚至在我写这个问题之前尝试提出的解决scheme,但没有“ErrorDocument 404”行,并没有工作。
编辑2:testing和另一个说明:
在testing期间,我使用查询string:/12345.css?v=5和/dir4/12345.css?v=3&t=66testing了URL [它工作正常,因为REQUEST_URI排除了查询string!]
非常重要的是要注意的是,服务器通常应该返回HTTP代码404丢失的文件(否则search引擎可以伤害你的排名)。 如果您将完整的域名设置为:ErrorDocument 404 http://mydomain.com/_code_404.html,那么“客户端将不会收到原始的错误状态码,而是会收到redirect状态码”。 (参考 – httpd.apache.org/docs/2.0/mod/core.html#errordocument)
仅在没有find文件时redirect请求?
.htaccess mod_rewrite的解释
重写问题 – L(ast)不被尊重?
Symfony从路由中移除前三个字符
在Nginx,htaccess上韭菜
你可以试试这个:
ErrorDocument 404 /_code_404.html <Ifmodulee mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_URI} !(robots.txt|sitemap.xml(.gz)?) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} .(css|js|bmp|gif|ico|jpe?g|jpe|png|swf)$ [NC] RewriteRule .* - [L] RewriteRule ^index.PHP$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.PHP [L] </Ifmodulee>
.htaccess通过PHP显示404,403,500,错误页面
如何从PHP文件中显示.htaccess显示错误?我的意思是当我搜索一个不存在的文件.htaccess应该显示error.PHP的错误页面,但error.PHP需要一个带错误代码的参数.
注意:.htaccess应该直接在当前URL上显示错误而不重定向.我能这样做还是不可能?还有其他方法吗?
解决方法:
您正在寻找ErrorDocument.
在.htaccess中指定要处理的代码,例如:
ErrorDocument 403 /error.PHP
ErrorDocument 404 /error.PHP
ErrorDocument 500 /error.PHP
并在error.PHP中,处理错误代码,如:
<?PHP
$code = $_SERVER['REDIRECT_STATUS'];
$codes = array(
403 => 'Forbidden',
404 => 'Not Found',
500 => 'Internal Server Error'
);
$source_url = 'http'.((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 's' : '').'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if (array_key_exists($code, $codes) && is_numeric($code)) {
die("Error $code: {$codes[$code]}");
} else {
die('UnkNown error');
}
?>
.htaccess重写规则冲突
我正在编写代码并构build一个htaccess文件,其中包含以下内容:
RewriteEngine on RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.PHP?id=$1 [NC,L] # Handle page requests RewriteRule ^category/([A-Za-z0-9-]+)/?$ category.PHP?cat=$1 [NC,L] # Handle category requests RewriteRule ^author/([A-Za-z0-9-]+)/?$ author.PHP?auth=$1 [NC,L] # Handle author requests
第一条规则正常,但后者似乎与第一条规则有冲突。 每当我访问一个url在http://example.com/category/foobar或http://example.com/author/fooauthor/我总是得到一个消息,该页面不能find,因为它仍然试图打开索引文件。
有没有可能解决这个问题?
Apache .htaccess盗链redirect
htaccess重写条件不起作用
build议将HTTP请求redirect到HTTPS的方法
.htaccess删除.html文件/目录的优先级重写
在特定的htaccess文件中search和replace – linux
.htaccess简短和友好的url
.htaccess与2个参数弄乱了CSS,JS,图像path
如何编辑htaccessredirect所有的交通到安全www域
“RewriteEngine不允许在这里”使用XAMPP .htaccess错误
Apache .htaccess vs httpd – 真的很重要吗?
您可以在最后一行设置一般规则:
RewriteEngine on RewriteRule ^category/([A-Za-z0-9-]+)/?$ category.PHP?cat=$1 [NC,L] RewriteRule ^author/([A-Za-z0-9-]+)/?$ author.PHP?auth=$1 [NC,L] RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.PHP?id=$1 [NC,L]
发生这个问题是因为第一行支持所有的URL
总结
以上是小编为你收集整理的.htaccess重写规则冲突全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
.htaccess重写规则的麻烦
我猜这个问题已经被问了很多次了,但是我找不到能给我所需要的东西。
所以..我可以通过以下url访问脚本:
http://website.com/index.PHP/hello/world http://website.com/hello/world
这两个去parsinginput(在这个例子中你好/世界)的index.PHP 。
这是我的.htaccess :
如何使用.htaccess规则去除百分比编码的斜杠?
URL重写和redirect(使用数据库数据)
用日历和分页htaccess获得价值
如何阻止POST请求的IP,但不是GET?
IndexIgnore *或Options -Indexes
<IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) index.PHP?path=$1&%{QUERY_STRING} [L] </IfModule>
然而。 当这个网站被这样访问时:
http://website.com/index.PHP/hello/world
RewriteRule输出类似于index.PHP?path = index.PHP / hello / world的东西
我想在RewriteRule中的 path =之后移除index.PHP
htaccess使用参数redirecturl
将文件夹redirect到包含文件夹的子域
如何停止inheritance父级的htaccess规则的子目录
htaccess重写QueryString在Apache 2.2中消失,但在2.4中工作
使用基于查询string参数的HTTP身份validation保护URL
你的.htaccess文件应该是这样的(注意检查index.PHP是否为url的一部分的新规则):
<Ifmodulee mod_rewrite.c> Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^index.PHP/(.*)$ index.PHP?path=$1&%{QUERY_STRING} [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) index.PHP?path=$1&%{QUERY_STRING} [L] </Ifmodulee>
尝试这个
RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.PHP [NC,L]
修改Stackoverflow答案来解决这个问题
.htaccess:
<Ifmodulee mod_rewrite.c> Options +FollowSymlinks RewriteEngine On # Redirect user RewriteCond %{THE_REQUEST} ^.*index.PHP.* RewriteRule ^(.*)index.PHP(.*)$ $1$2 [NC,R=301,L] # Handle the query to PHP RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) index.PHP?path=$1&%{QUERY_STRING} [L] </Ifmodulee>
总结
以上是小编为你收集整理的.htaccess重写规则的麻烦全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
.htaccess,将404错误重写到其他域
如何将所有的404错误redirect到另一个域?
我find了
Error 404 http://example.com/error.html
但是我需要:
if Error 404 (.*) http://example.com/$1
我试过了:
Apache htaccess 301redirect
我怎样才能设置CORS访问我的Linux Web服务器上的audio文件与Apache2?
用PHP / htaccess / mod_rewrite强制使用www前缀
为什么我的重写规则中不能有斜杠?
使用Mod_Rewrite将ROOT重写为另一个path
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ http://example.com/$1
但它redirect所有的请求,实际上,如果我运行一个.PHP脚本生成一个页面的一些404链接脚本的URL变成
http://example.com/script.PHP
相反,URL应该保持不变,只有404链接应该被redirect到其他域。
解决scheme?
重写代码从htaccess到Nginxconfiguration?
使用基本身份validation(htaccess)来限制对特定URL的访问
Apache .htaccess vs httpd – 真的很重要吗?
.htaccess使用GET参数redirect
IndexIgnore不允许在这里
1 – 像这样创建ErrorDocument指令:
ErrorDocument 404 /404.PHP
2 – 然后创建你的404.PHP像这样:
<?PHP if ($_SERVER["HTTP_HOST"] == "domain.com") // current domain header('Location: http://example.com' . $_SERVER["REQUEST_URI"],TRUE,301); ?>
更新只使用.htaccess:
RewriteCond %{HTTP_HOST} ^domain.com$ [NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ http://example.com%{REQUEST_URI} [L,R=301]
我们今天的关于使用.htaccess和ErrorDocument 404 +重写规则为某些文件types设置Web服务器句柄404错误的分享已经告一段落,感谢您的关注,如果您想了解更多关于.htaccess通过PHP显示404,403,500,错误页面、.htaccess重写规则冲突、.htaccess重写规则的麻烦、.htaccess,将404错误重写到其他域的相关信息,请在本站查询。
本文标签: