更改 public_html 目录 .htaccess

Lin*_*ing 0 apache directory .htaccess

我的 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>
Run Code Online (Sandbox Code Playgroud)

Joa*_*son 5

如果你只能选择 .htaccess,这个简单的应该可以;

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

解释;

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.
Run Code Online (Sandbox Code Playgroud)

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