简体   繁体   中英

Remove subfolder name from WordPress site using htaccess

I've moved WordPress into sub-folder named /site but the URL now shows http://www.example.com/site . I want it to show without the /site/ subdirectory.

Here's my current .htaccess code

RewriteEngine On
RewriteBase /site/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site/index.php [L]

How do I remove the physical subdirectory from the visible URL?

I advice you against messing up the contents of the .htaccess file. Revert the changes that you've made to this file and follow the simple procedue.

  1. Login to the admin dashboard.
  2. Go to Settings > General
  3. In the WordPress Address (URL) field type http://www.example.com/site
  4. In the Site Address (URL) field type http://www.example.com

Save the changes and you should be good to go.

According to Giving WordPress Its Own Directory in the Codex, this is what you need (works for me).

Create a .htaccess file in root folder, and put this content inside (just change example.com and my_subdir) :

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/my_subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /my_subdir/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ my_subdir/index.php [L] 
</IfModule>

There you will also find instructions to do it by changing the URL in the General Settings, which also requires you to copy .htaccess and index.php, and then edit this last. The first method seems easier.

Try following steps:-

1)Create the new location for the core WordPress files to be stored (we will use /wordpress in our examples). (On linux, use mkdir wordpress from your www directory. You'll probably want to use "chown apache:apache" on the wordpress directory you created.)
2)  Go to the General panel.
3) In the box for WordPress address (URL): change the address to the new location of your main WordPress core files. Example: http://example.com/wordpress 
4)  In the box for Site address (URL): change the address to the root directory's URL. Example: http://example.com 
5) Move your WordPress core files to the new location (WordPress address). 
6) Copy (NOT MOVE!) the index.php and .htaccess files from the WordPress directory into the root directory of your site (Blog address). The .htaccess file is invisible, so you may have to set your FTP client to show hidden files. If you are not using pretty permalinks, then you may not have a .htaccess file. If you are running WordPress on a Windows (IIS) server and are using pretty permalinks, you'll have a web.config rather than a .htaccess file in your WordPress directory. For the index.php file the instructions remain the same, copy (don't move) the index.php file to your root directory. The web.config file, must be treated differently than the .htaccess file so you must MOVE (DON'T COPY) the web.config file to your root directory.
7) go to index.php.... Change the following and save the file. Change the line that says:
require( dirname( __FILE__ ) . '/wp-blog-header.php' );

to the following, using your directory name for the WordPress core files:

require( dirname( __FILE__ ) . '/wordpress/wp-blog-header.php' );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM