Jump to content
Sign in to follow this  
Edison

Install Processwire in a Subdirectory

Recommended Posts

Personally when I install a CMS I prefer to set it inside a subdirectory rather than the root folder. 

There are different reasons for this choice. For example you may wish to have different CMS installed in different subdirectories; or multiple copies or versions of Processwire in different subdirectories; keep separated directories for production and development; and so on. Sometimes this choice is taken also to obfuscate your CMS contents.

In this forum I found some helpful hints, but I could not find a turn-key tutorial explaining the detailed steps for redirection and how to hide subfolder in urls' segments.

It's pretty easy. Just let's do it step by step.

We are going to create a new .htaccess file in the root folder (please note it is a new one, we will leave the .htaccess file in Processwire subfolder unchanged), where we will add the section described below. Just replace yoursite.com and yoursubfolder with ... your ones!

# .htaccess in root directory
# Redirect to Processwire subdirectory
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?yoursite.com$
RewriteCond %{REQUEST_URI} !^/yoursubfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /yoursubfolder/$1
RewriteCond %{HTTP_HOST} ^(www.)?yoursite.com$
RewriteRule ^(/)?$ yoursubfolder/index.php [L]
</IfModule>

With this approach we can protect root files and subdirectories from redirection.

Are we done ? Yes and no. After these modifications pages are redirected correctly, but in the browser link you will note that subfolder's name is still showing. This is not good, we want to hide it.

We are just one step away. Let's open our site/config.php and add the following line at the end:

/**
 * Set urls root to hide Processwire folder
 * This must be combined with .htaccess in root directory
 */
$config->urls->root = '/';

Do not forget to lock site/config.php after modifying it.

If you prefer, instead of modifying config.php, you can place the above line in _init.php.

And here it is! I hope this simple tutorial can be of help.

  • Like 6
  • Thanks 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...