我遇到了在子文件夹中运行Wordpress网站的一些问题。 结构是这样的:
home
.htaccess
- folder1
- wp
- folder2
- another wp (not important for this)
.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
# non-www domain
RewriteCond %{REQUEST_URI} !^/folder1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /folder1/$1
RewriteCond %{HTTP_HOST} ^(www.)?domain.tld$
RewriteRule ^(/)?$ folder1/index.php [L]
这很有效。每次我在浏览器中键入domain.tld,我都会转发到folder1中的index.php。 但它并没有为www.domain.tld做诀窍。我遇到了这种情况:
403禁止您无权访问/在此服务器上。
有谁知道什么样的.htaccess-code会正确转发所有www.domain.tld用户?
答案 0 :(得分:0)
您的.htaccess
文件没问题。我已经使用Debian设置了一个虚拟机,安装了Apache webserver并设置了一个像你一样的文件夹结构:
@ /var/www/domain.tld
20:18:12 $ ls -laR
.:
total 16
drwxr-xr-x 3 root root 4096 Jan 17 20:16 .
drwxr-xr-x 32 root root 4096 Jan 17 20:10 ..
drwxr-xr-x 2 root root 4096 Jan 17 20:11 folder1
-rw-r--r-- 1 root root 295 Jan 17 20:09 .htaccess
./folder1:
total 12
drwxr-xr-x 2 root root 4096 Jan 17 20:11 .
drwxr-xr-x 3 root root 4096 Jan 17 20:16 ..
-rw-r--r-- 1 root root 22 Jan 17 20:06 index.php
我已经像这样配置了Apache:
<VirtualHost *:80>
DocumentRoot /var/www/domain.tld
ServerName domain.tld
ServerAlias www.domain.tld
TransferLog /var/log/apache2/domain_tld_access.log
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/domain.tld>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/domain_tld_error.log
LogLevel warn
CustomLog /var/log/apache2/domain_tld_access.log combined
</VirtualHost>
.htaccess
文件与您的文件相同:
@ /var/www/domain.tld
20:18:37 $ cat .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
# non-www domain
RewriteCond %{REQUEST_URI} !^/folder1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /folder1/$1
RewriteCond %{HTTP_HOST} ^(www.)?domain.tld$
RewriteRule ^(/)?$ folder1/index.php [L]
PHP文件只输出“test”:
@ /var/www/domain.tld
20:19:18 $ cat folder1/index.php
<?php
echo "test";
?>
我已配置Windows计算机,以便domain.tld
可以实际解析。我编辑了文件C:\Windows\System32\drivers\etc\hosts
以包含VM的IP地址:
192.168.178.36 domain.tld
192.168.178.36 www.domain.tld
它有效: