【问题标题】:Change public_html directory .htaccess更改 public_html 目录 .htaccess
【发布时间】:2012-09-26 14:05:14
【问题描述】:

我的 public_html 文件夹是 /domain.com/public_html/ 但我希望 htaccess 将它们重定向到文件夹 /domain/public_html/www/ 但仍然将 domain.com 作为域而不是 domain.com/www 。

编辑: 我希望 public_html 中的子文件夹 www 是默认根目录,而不是 public_html 本身

对此有什么解决办法吗?

这是我目前的 htacess

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php
<IfModule mod_rewrite.c>
    RewriteEngine On    
    RewriteRule ^(.*)$ www/$1 [NC,L]
</IfModule>

【问题讨论】:

  • 我还没有尝试任何方法,因为我还没有找到任何解决方案
  • 这个问题目前的形式不精确且不清楚。请修改它并尝试更清楚地说明您想要发生的事情。并且不要混合使用域名、路径和网址等表达方式。
  • 添加了更多信息,希望能提供更好的问题来回答

标签: apache .htaccess directory


【解决方案1】:

尝试将其放在public_html 文件夹的 htaccess 中:

<IfModule mod_rewrite.c>
    RewriteEngine On    
    RewriteRule ^(.*)$ www/$1 [NC,L]
</IfModule>

编辑 apache 配置 (httpd.conf)

vi /usr/local/apache/conf/httpd.conf

并将域的DocumentRoot设置为

DocumentRoot /home/user/public_html/www

保存文件并重启httpd服务。

OR(推荐)

看看这个问题(它的答案)-https://stackoverflow.com/a/5891858/1361042

编辑

使用这个 HTACCESS:

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/www/
    RewriteRule ^(.*)$ www/$1 [NC, QSA]
</IfModule>

不要将它添加到你的,而是用这个替换你的 htaccess。

【讨论】:

  • 我厌倦了你展示的 mod_rewrite 解决方案,但它只是给出了 med 错误 500,我无法访问 httpd.conf,因为我在共享网络主机上。
  • 如果您无法访问 httpd.conf 文件,我恐怕无法更改默认根目录。
  • 我已向我的主机 (binero.se) 发送了一条消息,询问是否可以更改它。因为当我要让其他一些人通过 ftp 访问该站点时,这是一个安全原因
  • 我没有看到你当前的 htaccess,在我的回答中将其更改为我的编辑
【解决方案2】:

如果你只能去.htaccess,这个简单的应该可以做到;

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/www/
RewriteRule ^(.*)$ /www/$1 [QSA]

解释;

RewriteEngine on                      # Turn on mod_rewrite functionality
RewriteCond %{REQUEST_URI} !^/www/    # Don't rewrite requests that are 
                                      # already to the /www/ directory. 
                                      # If this isn't here, we'll go into
                                      # a neverending loop.
RewriteRule ^(.*)$ /www/$1 [QSA]      # Rewrite all else to the www subdirectory
                                      # QSA = keep the query string.

编辑:没有看到您现有的 htaccess,这个(减去多余的 RewriteEngine 语句)可能应该放在最后而不是整个 IfModule 块。

【讨论】:

    猜你喜欢
    • 2012-01-11
    • 2021-08-10
    • 1970-01-01
    • 2017-06-06
    • 1970-01-01
    • 2011-03-11
    • 2011-08-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多