Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.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
Php htcaccess重写到子目录不起作用_Php_Apache_Http_Web - Fatal编程技术网

Php htcaccess重写到子目录不起作用

Php htcaccess重写到子目录不起作用,php,apache,http,web,Php,Apache,Http,Web,当我再次问这个问题时,有些人可能会生气和恼怒,但在尝试了我在这里找到的所有答案后,我真的无法让它起作用,我也是这方面的新手。无论如何,我有一个域(www.testco.sample.com),我想重定向到一个子目录(/var/www/html/start/index.html),所以我修改了.htaccess并添加了以下几行 RewriteEngine on RewriteRule ^$ start/index.html [L] 但是,重新启动apache时,它不使用重写规则。我甚至试过下面的

当我再次问这个问题时,有些人可能会生气和恼怒,但在尝试了我在这里找到的所有答案后,我真的无法让它起作用,我也是这方面的新手。无论如何,我有一个域(www.testco.sample.com),我想重定向到一个子目录(/var/www/html/start/index.html),所以我修改了.htaccess并添加了以下几行

RewriteEngine on
RewriteRule ^$ start/index.html [L]
但是,重新启动apache时,它不使用重写规则。我甚至试过下面的代码,但都没有用

# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subdirectory/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /subdirectory/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ subdirectory/index.html [L] 
有人能解释一下怎么做吗


谢谢。

使用
RewriteBase

# .htaccess main domain to subdirectory redirect
RewriteBase /foldername/
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subdirectory/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /subdirectory/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ subdirectory/index.html [L] 

这很尴尬,但我的问题的解决方法非常简单,我不得不花4-6个小时搜索、排除故障,寻找答案(讽刺!)。解决我的问题的是一条直线

RedirectMatch ^/$ /start/index.html

谢谢你们的帮助,伙计们

你允许虚拟主机覆盖吗?是的,我做了第一件事,我检查了。如果服务器是Ubuntu,有什么区别吗?也许我错过了什么。