3

I am having a tough time removing the subfolders from the URL in my WordPress site.

Currently, the URL format is: www.mysite.com/subfolder/index.php/category/postname

I would like to remove both the subfolder AND index.php from the URL.

The site must stay in a subfolder of root on my server.

My current htaccess file is:

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

I've tried to add the following, although it did not work.

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^subfolder/(.*)$ http://www.mysite.com/$1 [R=301,L]
RewriteRule .* index.php/$0 [PT,L] 

2 Answers 2

1

You need to make the WP site url and home url differ in Settings / General. The home url should be example.com, while the site url (where WP lives) should be example.com/wp (or wherever you put it).

You can hardcode these in your config file:

define('WP_HOME',    'http://example.com');
define('WP_SITEURL', 'http://example.com/wp');

WP should know how to take things from there, and place the .htaccess where it should be.

In case it doesn't, my own site's folder looks like this:

  • .htaccess
  • index.php
  • wp

The index.php file contains:

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

And the .htaccess contains:

# 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

Regarding the /index.php bit in URLs generated by WP, it means WP is (incorrectly?) finding that your site cannot manage permalinks. (Can I wager that this is because you're using Nginx?)

Assuming you know better than WP, add a must-use plugin in your wp-content/mu-plugins folder, e.g. a force-permalinks.php file:

<?php
add_filter( 'got_rewrite', '__return_true' );
1

Not sure what exactly you want. Can you please elaborate your question a bit more?

If you want URLs like www.mysite.com/subfolder/postname (where the subfolder is where your WordPress install is), then just go to Settings > Permalinks and change it to Post Name.

EDIT

If your WordPress install is in subfolder and you want URLs like www.mysite.com/category/postname, then set both the WordPress Address and Site Address to www.mysite.com and in Permalinks, choose Custom Structure and use this tag /%category%/%postname%.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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