重写的.htaccess和子域

编程入门 行业动态 更新时间:2024-10-19 02:23:10
本文介绍了重写的.htaccess和子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个子域设置为onlinedev.domain我需要使用htaccess的重写,以domain/online_content,同时还显示出onlinedev.domain在地址栏(SSL是onlinedev.domain)。这是我目前有非常接近:

I have a subdomain setup as onlinedev.domain I need to use htaccess to rewrite to domain/online_content, while still showing onlinedev.domain in the address bar (SSL is for onlinedev.domain). this is what I currently have that is very close:

php_flag display_errors off RewriteEngine On RewriteCond %{HTTP_HOST} !^$ RewriteCond %{HTTP_HOST} onlinedev\.domain\$ [NC] RewriteCond %{HTTP_HOST}<->%{REQUEST_URI} ^(www\.)?([^.]+).*<->/([^/]+) [NC] RewriteCond %2<->%3 !^(.*)<->\1$ [NC] RewriteRule ^(.+) /%2/$1 [L]

这正确改写为domain/onlinedev~~V,但如果我尝试将重写规则更改为:

This correctly rewrites to domain/onlinedev, but if I try to change the RewriteRule to:

RewriteRule ^(.+) /online_content/$1 [L]

我得到一个错误

据我所知,通常有更好的方法来做到这一点子的工作,但没有进入服务器配置和DNS的细节,我需要htaccess的做到这一点。

I understand that there are typically better ways to do this subdomain work, but without getting into server config and DNS details, I need to do it with htaccess.

是的,我确实需要重写,以具有比子不同名称的目录。

And yes, I do need to rewrite to a directory that has a different name than the subdomain.

推荐答案

好吧,我想通了。问题是,我是引起无限循环。一旦重写已经发生了,它仍在试图重写的目录。这里是我的照顾它新的htaccess:

Well, I figured it out. The issue was that I was causing an infinite loop. Once the rewrite had happened, it was still trying to rewrite to the directory. Here is my new htaccess that took care of it:

RewriteEngine On RewriteCond %{HTTP_HOST} !^$ RewriteCond %{HTTP_HOST} onlinedev\\.domain\\$ [NC] RewriteCond %{REQUEST_URI} !^/online_content/ RewriteRule ^(.+) /online_content/$1 [L]

这是我添加了一个检查,以确保该REQUEST_URI是不是我重写了目录的名称的通知。

Notice that I added a check to make sure that the REQUEST_URI is not the name of the directory I am rewriting to.

更多推荐

重写的.htaccess和子域

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

发布评论

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

>www.elefans.com

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