htaccess 重写到子目录不起作用
htcaccess rewrite to subdirectory not working
一旦我再次问这个问题,有些人可能会生气和恼怒,但在尝试了我在这里找到的所有答案后,我无法真正让它发挥作用,而且我也是这方面的新手。无论如何,我有一个域 (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/
# 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/
# 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
谢谢大家的帮助!
一旦我再次问这个问题,有些人可能会生气和恼怒,但在尝试了我在这里找到的所有答案后,我无法真正让它发挥作用,而且我也是这方面的新手。无论如何,我有一个域 (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/
# 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/
# 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
谢谢大家的帮助!