重写的.htaccess和子域 [英] .htaccess rewrite and subdomains

查看:100
本文介绍了重写的.htaccess和子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a subdomain setup as onlinedev.domain.com I need to use htaccess to rewrite to domain.com/online_content, while still showing onlinedev.domain.com in the address bar (SSL is for onlinedev.domain.com). 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\.com$ [NC] 
RewriteCond %{HTTP_HOST}<->%{REQUEST_URI} ^(www\.)?([^.]+).*<->/([^/]+) [NC] 
RewriteCond %2<->%3 !^(.*)<->\1$ [NC] 
RewriteRule ^(.+) /%2/$1 [L]

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

This correctly rewrites to domain.com/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\\.com$ [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和子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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