Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache htaccess子域到文件夹重定向_Apache_.htaccess_Mod Rewrite_Redirect_Subdomain - Fatal编程技术网

Apache htaccess子域到文件夹重定向

Apache htaccess子域到文件夹重定向,apache,.htaccess,mod-rewrite,redirect,subdomain,Apache,.htaccess,Mod Rewrite,Redirect,Subdomain,我需要重定向(透明)到 在Apache2中,我编辑了mywebsite.com.conf文件,在VirtualHost部分添加了ServerAlias*.mywebsite.com。然后,我在webmin中重新启动了Apache服务 最后,我创建了一个新的.htaccess规则: RewriteEngine on RewriteCond %{HTTP_HOST} !^www.mywebsite.com$ [NC] RewriteCond %{HTTP_HOST} ^test\.mywebsite

我需要重定向(透明)到

在Apache2中,我编辑了mywebsite.com.conf文件,在VirtualHost部分添加了ServerAlias*.mywebsite.com。然后,我在webmin中重新启动了Apache服务

最后,我创建了一个新的.htaccess规则:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.mywebsite.com$ [NC]
RewriteCond %{HTTP_HOST} ^test\.mywebsite\.com [NC]
RewriteRule (.*) http://www.mywebsite.com/test/$1 [L,R=301]
但是,我有一个页面未找到错误,现在我不知道该怎么办

有什么建议吗?谢谢

编辑

以下是完整的.htaccess文件:

SetEnv REGISTER_GLOBALS 0

# MASK FILES IN DIRECTORIES
Options -Indexes
Options -MultiViews

RewriteEngine on

RewriteCond %{HTTP_HOST} ^mywebsite\.com$ [NC]
RewriteRule ^(.*) http://www.mywebsite.com/$1 [QSA,R=301,L]

RewriteCond %{HTTP_HOST} !^www.mywebsite.com$ [NC]
RewriteCond %{HTTP_HOST} ^test\.mywebsite\.com [NC]
RewriteRule (.*) http://www.mywebsite.com/test/$1 [L,R=301]
编辑2

这是我的VirtualHost文件:

<VirtualHost ***.***.***.***:80>
SuexecUserGroup "#1011" "#1008"
ServerName mywebsite.com
ServerAlias www.mywebsite.com
ServerAlias webmail.mywebsite.com
ServerAlias admin.mywebsite.com
ServerAlias *.mywebsite.com
DocumentRoot /home/mywebsite/public_html
ErrorLog /var/log/virtualmin/mywebsite.com_error_log
CustomLog /var/log/virtualmin/mywebsite.com_access_log combined
ScriptAlias /cgi-bin/ /home/mywebsite/cgi-bin/
ScriptAlias /awstats/ /home/mywebsite/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/mywebsite/public_html>
Options -Indexes +IncludesNOEXEC +FollowSymLinks +ExecCGI
allow from all
AllowOverride All
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
FCGIWrapper /home/mywebsite/fcgi-bin/php5.fcgi .php
FCGIWrapper /home/mywebsite/fcgi-bin/php5.fcgi .php5
</Directory>
<Directory /home/mywebsite/cgi-bin>
allow from all
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.mywebsite.com
RewriteRule ^(.*) https://mywebsite.com:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.mywebsite.com
RewriteRule ^(.*) https://mywebsite.com:10000/ [R]
RemoveHandler .php
RemoveHandler .php5
IPCCommTimeout 31
FcgidMaxRequestLen 1073741824
<Files awstats.pl>
AuthName "mywebsite.com statistics"
AuthType Basic
AuthUserFile /home/mywebsite/.awstats-htpasswd
require valid-user
</Files>
RedirectMatch /cgi-bin/mailman/([^/\.]*)(.cgi)?(.*) https://mywebsite.com:10000/virtualmin-mailman/unauthenticated/$1.cgi$3
RedirectMatch /mailman/([^/\.]*)(.cgi)?(.*) https://mywebsite.com:10000/virtualmin-mailman/unauthenticated/$1.cgi$3
Alias /pipermail /var/lib/mailman/archives/public
</VirtualHost>

此规则将test.mywebsite.com重定向到mywebsite.com/index.php?sub=

您的
.htaccess
还有其他内容吗?文件夹
test
是否存在?访问的文件或地址是否存在?文件夹测试存在,地址(mywebsite.com)也存在。我用full.htaccess.html更新了这个问题,如果您在test文件夹中创建一个名为
test.html
的文件,并访问
test.domain.com/test.html
它是否有效,根据您当前的规则,它应该将您发送到
www.domain.com/test/test.html
?另外,您不需要
RewriteCond%{HTTP\u HOST}^www.mywebsite.com$[NC]
在您的第二条规则中,因为下一个条件已经说明HTTP是否以
test.domain.com
开头,请将其发送到那里。当您收到
页面未找到错误时
它在浏览器中显示了什么URL?@Prix:它不起作用。
RewriteCond %{HTTP_HOST} ^test\.mywebsite\.com [NC]
RewriteRule (.*) http://mywebsite.com/index.php?sub=$1 [L,R=301]