子域名重定向与htaccess以及一个500内部服务器错误 [英] Subdomain redirection with htaccess and a 500 Internal Server Error

查看:307
本文介绍了子域名重定向与htaccess以及一个500内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的.htaccess文件,因为某些原因,导致500内部服务器错误,当我试图重定向这样的子域:

My .htaccess file is, for some reason, causing 500 Internal Server Errors when I'm trying to redirect a subdomain like this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com [NC]
RewriteRule ^(.*)$ folder/anotherfolder/$1 [L]

我目前的主机不自行重定向子域名,所以我必须做这种方式。我正在努力实现的是,当用户输入 http://subdomain.domain.com/ ,他真的看到的http:// domain.com/folder/anotherfolder 。但是,我不希望在地址栏中的域名本身的改变。子站点本身,显然,主域名的别名,从而指向同一个文件夹作为主域名。

My current host doesn't redirect subdomains by themselves, so I have to do it this way. What I'm trying to achieve is that when a user enters http://subdomain.domain.com/, he really sees http://domain.com/folder/anotherfolder. I, however, don't want the domain itself on the address bar to change. The subdomain itself is, apparently, an alias of the main domain and thus points to the same folder as the main domain.

以上code也适用时,正则表达式导致它作为一个GET,因为这样的:

The above code also works when the regex result it used as a GET, as such:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com [NC]
RewriteRule ^(.*)$ folder/anotherfolder/index.php?p=$1 [L]

在GETP的值,然而,这不是例如test.php的(如果你试图访问subdomain.domain.com/test.php),但是从主域(即文件夹/ anotherfolder / test.php的)。

The value of the GET "p", however, is not e.g. "test.php" (if you tried to access subdomain.domain.com/test.php), but the whole path from the main domain (i.e. folder/anotherfolder/test.php).

任何想法,我做错了什么?

Any ideas what I'm doing wrong?

推荐答案

嗯,似乎已经引起的内部重定向循环。通过这样做修正:

Ah, seems to have been caused by an internal redirection loop. Fixed by doing this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain.domain.com [NC]
RewriteRule ^folder/anotherfolder/ - [L]
RewriteRule (.*) folder/anotherfolder/$1 [L]

有趣的是,答案通常揭示自己,你问过别人之后。

Funny how the answer usually reveals itself right after you've asked someone.

这篇关于子域名重定向与htaccess以及一个500内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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