0

I have an .htaccess file in the root directory of all my sites which handles canonical rewrites. The entire content of the .htaccess file is as follows:

Options +Indexes
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.domain.com/$1/ [L,R=301]

The trouble is, when I install a Wordpress blog in a subdirectory (/blog) the WP blog becomes inoperable. I cannot log into the wp-admin area. My host tells me that this is because of the .htaccess file in the root. Therefore this needs to be deleted.

So how do I achieve the same canonical URL rewrite instructions if I can't have an .htaccess file in the root? Can I have these instructions in a robots.txt file in the root? Or is there another way of doing this?

Lance Roberts
  • 22,383
  • 32
  • 112
  • 130

1 Answers1

1

If you document root is /var/www/my-site/ and you want to have wordpress in /var/www/my-site/blog you need to do the following:

1.) Create an index.php file the following content and put it into /var/www/my-site

<?php
    define('WP_USE_THEMES', true);
    require('./blog/wp-blog-header.php');
?>

2.) Put the following .htaccess into /var/www/my-site

# Redirect http://example.com to http://www.example.com
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L] 

# BEGIN WordPress
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Now the way you access your admin area is http://www.example.com/blog/wp-admin

Then in your dashboard, go to the settings and set WordPress Address URL to http://www.example.com/blog and the Site URL to http://www.example.com

scibuff
  • 13,377
  • 2
  • 27
  • 30