Remove subfolder name from WordPress site using htaccess

被刻印的时光 ゝ 提交于 2019-12-20 05:12:10

问题


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?


回答1:


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.




回答2:


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.




回答3:


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' );


来源:https://stackoverflow.com/questions/37346476/remove-subfolder-name-from-wordpress-site-using-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!