.htacess如果文件不存在,则执行重写

编程入门 行业动态 更新时间:2024-10-27 21:11:24
本文介绍了.htacess如果文件不存在,则执行重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有两个单独的.htaccess文件,我希望将它们融合在一起,以便始终优先执行第一次重写,这会将一些流量重定向到基于该域的https。然后,如果网址中的文件不存在,则将流量发送到php文件。这是一个网址缩短器,但是如果返回404,则显示404错误页面。

I have two separate .htaccess files that I'd like to be fused together so that the first rewrite always takes precedence, which redirects some traffic to https base which domain. Then if the file at the url does not exist, then it sends the traffic to a php file. It is a url shortener, but if that returns at 404, then it shows a 404 error page.

以下是.htaccess文件的详细内容:

Here are the bits and pieces of the .htaccess files:

下面,我相信应该将除kore.tt和korett以外的所有http流量重定向到https:

This, below, I believe should redirect all http traffic except kore.tt and korett to https:

RewriteEngine on RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} !^(www\.)?(kore\.tt|korett\) [NC] RewriteRule ^ %{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]

这是来自网址缩短程序的东西,应该将不存在的流量发送到loader.php

This is something from the url shortener that is supposed to send traffic that doesn't exist to loader.php

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ /loader.php [L] </IfModule>

但是如果返回404错误。这就是简单的404错误捕获。

But then if that returns a 404 error. Then this is the simple 404 error catch.

ErrorDocument 404 /404.html

推荐答案

您可以在htaccess中使用条件。还有许多创建规则的方法。看看是否可以为您工作。

You can use a condition in your htaccess. There are many more ways to create rules. See if this can work for you.

#check to see if loader.php exists on the filesystem, then do rewrite <If "-f %{DOCUMENT_ROOT} . '/loader.php'"> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ /loader.php [L] </If> #otherwise redirect to 404 page <Else> RewriteEngine On RewriteRule ^ /404.html [R=404,L] </Else>

更多推荐

.htacess如果文件不存在,则执行重写

本文发布于:2023-10-28 18:50:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537475.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不存在   重写   文件   htacess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!