0

I am encountering some issues running a Wordpress-site in a subfolder. The structure is like this:

 home
   .htaccess
   - folder1
     - wp
   - folder2
     - another wp (not important for this)

The .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]

This works well. Everytime I type domain.tld in my browser I am forwarded to the index.php in folder1. But it doesn't do the trick for www.domain.tld. I get in that case:

403 Forbidden You don't have permission to access / on this server.

Has anybody an idea what kind of .htaccess-code would forward all www.domain.tld users correctly?

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
Christoph
  • 1
  • 2

1 Answers1

0

Your .htaccess file is fine. I have set up a virtual machine with Debian, installed the Apache webserver and set up a folder structure like you did:

@ /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

I have configured Apache like this:

<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>

The .htaccess file is identical to yours:

@ /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]

The PHP file will simply output "test":

@ /var/www/domain.tld
20:19:18 $ cat folder1/index.php
<?php
echo "test";
?>

I have configured my Windows machine so that domain.tld can actually be resolved. I edited the file C:\Windows\System32\drivers\etc\hosts to contain the IP address of the VM:

192.168.178.36  domain.tld
192.168.178.36  www.domain.tld

And it works:

Screenshot FF

Screenshot Opera

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222