2

I've created a dynamic virtual host using this configuration file:

UseCanonicalName Off
<VirtualHost *:80>
    ServerName %1.dev
    ServerAlias *.%1.dev

ServerAdmin daniel@localhost
VirtualDocumentRoot /home/daniel/public_html/%1

LogLevel error rewrite:trace8 proxy:trace2

ErrorLog /home/daniel/public_html/error.log
CustomLog /home/daniel/public_html/access.log combined

&lt;Directory ~ &quot;/home/daniel/public_html/.*&quot;&gt;
    Options Indexes FollowSymlinks Multiviews
    AllowOverride All
    Require all granted
    DirectoryIndex index.php index.html
    RewriteEngine On

    &lt;FilesMatch &quot;\.php$&quot;&gt;
        SetHandler &quot;proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost:9000&quot;
    &lt;/FilesMatch&gt;
&lt;/Directory&gt;

</VirtualHost>

This works fine with php scripts, but I can't make it work with SEF URLs such as those used by WordPress (e.g. http//mysite.dev/blog return 404).

Any ideas on this?

sotirov
  • 4,455

2 Answers2

0

To make that work you need to enable rewrite module in Apache.

See this: https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-14-04

After you have the module you will need something like this (wordpress example):

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

This should be placed in either .htacccess file or vhost file.

  • Yes, I've tried that. This is what I currently have in my .htaccess file:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteRule ^index\.php$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    The problem is that this seems to be telling php-fpm to look for the php script in the /var/www/html directory (Apache's global DOCUMENT_ROOT), instead of /home/daniel/public_html/my-wp-site

    – danielperaza Jul 24 '17 at 19:24
0

Check your Apache config file and enable rewrite for all.

Open terminal and write: nano /etc/apache2/apache2.conf

Find these lines and write exactly this code :

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Change AllowOverride none to AllowOverride All.

sotirov
  • 4,455
Pejman Zeynalkheyri
  • 187
  • 1
  • 1
  • 10