4

I installed WP in subfolder /cms and it runs live without subfolder. When I use /%postname%/ as permalink I get 404 error on my site. My Server supported mod_rewrite.

My Code

wp-config.php

define('WP_SITEURL', 'http://www.sitename.de/cms');
define('WP_HOME', 'http://www.sitename.de');

root

1) .htaccess

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

2) index.php

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

/cms

1) .htaccess

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

2) index.php

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

Thanks for your help
Ogni

3

What I generally do

  • Install WP in sub directory.
  • Open permalink set required permalink.
  • Open settings->general link
  • Remove the sub directory name from 'Site Address (URL)'
  • Cut the index.php and .htaccess files from sub directory and paste them to root
  • change code in index.php as you did.
  • Again access settings->permalink save the form

Done. You dont need index.php and .htaccess file in sub directory.

1
  • 1
    Strange enough, this goes against what's in the codex Giving_WordPress_Its_Own_Directory. There they say to keep a copy of both index.php and .htaccess. Any hint on this? Please note: I'm not an .htaccess expert, and there's still something not clear about how should those file look in each folder.
    – superjos
    Jan 28 '14 at 10:07
1

I had similar issue and issue was not in code but was in httpd file

  1. Open the Apache configuration file located at/etc/httpd/conf/httpd.conf (or apache.conf for ubuntu)
  2. Change AllowOverride None to AllowOverride All inside the DocumentRoot Directory Directive, normally
1
  • This saved my day. When usual instruction does not work something fishy goes around. I guess this should be added to the codex manual about changing to subfolder.
    – Ehsan88
    Aug 21 '20 at 4:17
1

my solution to this problem, wich always works in my case;

create a .htaccess file in the subdirectory and add the code wich is generated when you change the permalinks on the bottom of the page.

example of the generated code;

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /kimco/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /kimco/index.php [L]
</IfModule>
1
  • 1
    Are you saying that both .htaccess files (in root and subdir) should have the same contents? E.g. both with RewriteBase /kimco/ ?
    – superjos
    Jan 28 '14 at 10:11
0

Get rid of the .htaccess file under /cms and then visit Settings -> Permalinks to flush your rewrite rules. Also make sure the site URL and home URL are set up in the database correctly (like you have in the wp-config).

3
  • 2
    if you define site and home url in wp-config, whatever is in the database will be ignored
    – Milo
    Oct 6 '12 at 15:27
  • @Milo: Thats right When I refresh my permalinks (wp admin-area), root .htaccess looks like: .. RewriteBase / ... RewriteRule . /index.php [L] but I think it should looks like: ... RewriteBase /cms ... RewriteRule . /cms/index.php [L]
    – ogni
    Oct 6 '12 at 18:40
  • in the root, i think it should look like RewriteBase / as it apparently does after refreshing permalinks. Did that solve it ?
    – commonpike
    Feb 8 '13 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.