【发布时间】:2016-06-06 09:33:16
【问题描述】:
我尝试阅读许多有关 htaccess 的答案,但找不到出路。 在虚拟主机中映像此架构:root/public_html/subfolder 现在使用 htaccess 文件中的以下代码(放置在 public_html 中)我可以管理,当在浏览器中键入域时,访问者会进入没有数字 example.com/subfolder 的子文件夹,example.com 就足够了。有用。 我现在想要的是,访问者不会被重定向到子文件夹中,而是在放置在根目录内的“额外文件夹”中(级别根目录与放置 public_html 文件夹但不在 public_html 内的同一级别)。 那么如何修改这段代码:
# .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} !^/subfolder/
# 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 ^(.*)$ /subfolder/$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 ^(/)?$ /subfolder/index.html [L]
我尝试用 ../extrafolder/ 更改 /subfolder/ (假设双点会向上推一级)但不起作用。 任何想法? 谢谢
【问题讨论】:
-
这应该是2部分的buzzle游戏,你只是把它的第二部分.htaccess配置,但第一部分是apache站点配置虚拟主机,你可以在/etc/apache2中找到它/sites-enabled/ 如果您使用的是基于 Linux 的系统。如果您需要明确的答案可能对您有所帮助,您也需要放置 apache 配置。
-
谢谢你回答我。我检查但我没有那个文件/文件夹等。我最终可以创建一个 Apache 处理程序。还有其他想法吗?
-
好的,我会在答案中设置它。
标签: .htaccess mod-rewrite url-rewriting document-root public-html