DEV Community

Lee Wynne
Lee Wynne

Posted on • Edited on

Wordpress blog in a Rails app subfolder ๐Ÿ™ˆ

Hello peeps ๐Ÿ‘‹๐Ÿผ

As anyone in the Dev community successfully added a Wordpress blog to a subfolder in a rails app?

myapp.com (rails)
myapp.com/blog (wordpress)

I have done a few rounds of googling but havenโ€™t yielded any confident results.

I am thinking that page rules within Cloudflare might be the answer but apparently Wordpress likes to be at the root domain or subdomain.

I know I could use Rails as the blog but I canโ€™t be ๐Ÿ‘โ€™sed atm as I can just use the huge Wordpress plugin systems for stuff I need quickly.

Thanks ๐Ÿ˜Š and in return I can do portraits of anyone that can shed clear informations on said subject.

Top comments (5)

Collapse
 
nuckfuggets profile image
Joren Rothman

You could try the following

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

# END WordPress
Enter fullscreen mode Exit fullscreen mode
Collapse
 
leewynne profile image
Lee Wynne

Thanks, is this in a config file?

Collapse
 
nuckfuggets profile image
Joren Rothman

It is the .htaccess file inside of the root folder of WordPreas

Collapse
 
codebjorn profile image
Dorin Lazar

I had such experience using Laravel app and for blog WordPress app. To make it possible I used nginx web server
The idea is pretty simple:

  1. Setup app folders, as example
var/www/laravel -> laravel app
var/www/wp -> wp app
Enter fullscreen mode Exit fullscreen mode
  1. Setup nginx server block
server {
    listen 80;
    index index.php index.html;
    root /var/www/laravel;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location /blog {
      alias /var/www/wp;
   }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php7.4-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
leewynne profile image
Lee Wynne

Thanks!