我有一个子域设置为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和子域
发布评论