Friday, March 2, 2018

Get wordpress running from different location without changing much in code.

In my instance the website was under /var/www/html and my apache2.conf says <Directory /var/www>

My .htaccess file under /var/www/html/ is and that is standard.


# 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


Lets say we want to keep all urls the samebut want to keep the file under /var/www/html/mywordpress/
To achive this do the following

mkdir /var/www/html/mywordpress/
make sure all the permissions are correct.

mv /var/www/html/* /var/www/html/mywordpress/
mv /var/www/html/mywordpress/.htaccess /var/www/html/mywordpress/.htaccess.old

vi /var/www/html/.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/mywordpress/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mywordpress/$1
RewriteRule ^(/)?$ mywordpress/index.php [L]
</IfModule>

# END WordPress


restart the apache

sudo apachectl restart


Done!!!

No comments: