0

I have scoured several pages, answers and articles in an attempt to correctly configure Apache Alias and Wordpress Permalinks without success.

/var/www/
| - example.com (Custom Web App)
| - blog.example.com (Wordpress)

Using the structure above, I am able to access Wordpress without any issues, including permalinks such as https://blog.example.com/sample-post/.

I have added an alias in Apache as shown below:

<VirtualHost *:443>
    ServerName example.com
    DocumentRoot /var/www/example.com/public
    Alias /blog /var/www/blog.example.com

    <Directory /var/www/example.com/public>
            AllowOverride all
            Options -Multiviews
            Require all granted
    </Directory>
</VirtualHost>

After making those changes, restarting apache and updating the wordpress address and site address in the WordPress settings area, I can access the site at the desired URL https://example.com/blog but permalinks return 404 errors.

I find that I must switch to plain URLs to get posts to load. I have made no changes to the .htaccess file, however this is the content:

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

The objective is to access WP posts at https://example.com/blog/sample-post/

Any help is appreciated.

Ralph
  • 862
  • 11
  • 26
  • What format do your permalinks look like? Presumably they are of the desired format, ie. `https://example.com/blog/2018/06/sample-post/`? The `.htaccess` file above is presumably the one located at `/var/www/blog.example.com/.htaccess`? Do you have a `.htaccess` file at `example.com` or any other server directives that might influence this? – MrWhite Jun 24 '18 at 21:59
  • @MrWhite - Correct, I missed that. Can you please update your comment? Desired format is `https://example.com/blog/%postname%/` and yes the .htaccess above is from within the WP directory (`/var/www/`blog.example.com/`) – Ralph Jun 24 '18 at 23:23
  • Your server config/`.htaccess` looks OK to me. I think this might be more of a WordPress issue. I believe WP also stores the absolute URL(s) in the database, which will also need to be updated. Maybe you could get around this configuring a reverse proxy instead of using an `Alias`? – MrWhite Jun 25 '18 at 00:36

1 Answers1

1

I solved the same issue by changing the configuration.

When you use Alias /blog then accessing WP posts using permalink example.com/blog/sample-post/ will be redirected to example.com by Apache so you get 404 error.

I was using Reverse Proxy and to ignore redirects my setting was:

<Location /blog/>
  RewriteEngine off
  ProxyPass !
</Location>

Now for Alias /blog we should change following RewriteRule to apache configuration to allow permalinks wroks:

<Location /blog/>
  RewriteEngine off
  ProxyPass !
  <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]
  </IfModule>
</Location>

It works for me.

Priyesh
  • 111
  • 2