如果 URL 不包含特定字符串,则 HTACCESS 重定向 [英] HTACCESS redirect if URL does not contain specific string

查看:77
本文介绍了如果 URL 不包含特定字符串,则 HTACCESS 重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经浏览了此处的各种其他帖子,但似乎找不到任何说明如果 url 不包含特定字符串的情况下如何在 HTACCESS 中进行重定向.我需要做的是对所有请求强制使用 HTTPS/WWW,除非请求是针对 appfeed.domain.com.在这种情况下,我根本不想重定向,而只是让请求通过.

I have looked through various other posts on here but I can't seem to find any that show how to do a redirect in HTACCESS if the url does NOT contain a specific string. What I need to do is force HTTPS/WWW to all requests unless the request is for appfeed.domain.com. In that case, I don't want to redirect at all but just let the request go through.

这是我现在所拥有的.

RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]

这有效,但它也会将我的 appfeed.domain.com 请求重定向到 www.appfeed.domain.com,这显然破坏了请求.有人可以帮我吗?

This works, but it also redirects my appfeed.domain.com requests to www.appfeed.domain.com, which obviously breaks the request. can anyone help me out here?

推荐答案

您能否尝试按照您显示的示例编写.这将仅处理不是 appfeed.domain.com 的域的请求.根据 OP 的 htaccess 本身和其余条件添加第一个条件.

Could you please try following, written as per your shown samples. This will process requests only for for domain which is not appfeed.domain.com. Adding 1st condition as per of that and rest of the conditions from OP's htaccess itself.

RewriteEngine ON
RewriteCond %{HTTP_HOST} !appfeed\.domain\.com [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]

这篇关于如果 URL 不包含特定字符串,则 HTACCESS 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆