Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess to rewrite wordpress subdirectory with permalinks to root

I have a wordpress site installed in the directory "wp". I want to keep it in that folder for maintenance purposes. Wordpress gives the option to create a htaccess for permalinks. You can see that code (which works) below.

What I want is a rewriterule so - to visitors - the site appears to be in the root. I've to change the rewritebase, but that didn't work.

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

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]
</IfModule>
like image 241
SPRBRN Avatar asked Apr 06 '11 10:04

SPRBRN


3 Answers

1) in your dashboard, go to settings -> general and make sure
a) wordpress directory -> http://mydomain.com/wp
b) site address -> http://mydomain.com

2) move your index.php from subdirectory to the root (MOVE, don't just copy)

3) edit your index.php to read

/** Loads the WordPress Environment and Template */
require('./wp/wp-blog-header.php');

where "wp" is your subdirectory

4) delete any .htaccess file in the subdirectory

5) add this to your .htaccess in the root

# 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

Under this setup, your wordpress installation will be located in /wp/ directory. Visitors will visit your site using http://mydomain.com. Good luck.

like image 167
csi Avatar answered Nov 13 '22 15:11

csi


What would you think of that :

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /wp/index.php [L]


RewriteCond %{REQUEST_URI} !^/wp/.*$
RewriteRule ^(.*)$ /wp/$1 [L]

You rewrite all non existing things to /wp/index.php, and all non /wp/ file to a /wp/ equivalent file. So if you call index.php it's in fact /wp/index.php

like image 37
M'vy Avatar answered Nov 13 '22 14:11

M'vy


For a site with two WordPress blogs, one at the site root, and one in a subfolder, i.e. https://example.com/ and https://example.com/otherblog/, here's what i did

<Directory /data/sites/example.com/otherblog>
  <IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index.php$ - [L] 
  RewriteCond %{REQUEST_FILENAME} !-f 
  RewriteCond %{REQUEST_FILENAME} !-d 
  RewriteRule . /otherblog/index.php [L] 
  </IfModule>
</Directory>


<Directory /data/sites/example.com>
  <IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index.php$ - [L] 
  RewriteCond %{REQUEST_FILENAME} !-f 
  RewriteCond %{REQUEST_FILENAME} !-d 
  RewriteRule . /index.php [L] 
  </IfModule>
</Directory>
like image 1
Paul Schreiber Avatar answered Nov 13 '22 14:11

Paul Schreiber