简体   繁体   English

使用htaccess从WordPress站点删除子文件夹名称

[英]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 . 我已将WordPress移动到名为/site子文件夹中,但URL现在显示为http://www.example.com/site I want it to show without the /site/ subdirectory. 我希望它显示没有/site/子目录。

Here's my current .htaccess code 这是我目前的.htaccess代码

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? 如何从可见URL中删除物理子目录?

I advice you against messing up the contents of the .htaccess file. 我建议你不要弄乱.htaccess文件的内容。 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 在WordPress地址(URL)字段中键入http://www.example.com/site
  4. In the Site Address (URL) field type http://www.example.com 在站点地址(URL)字段中键入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). 根据法典中给予WordPress自己的目录 ,这是你需要的(适合我)。

Create a .htaccess file in root folder, and put this content inside (just change example.com and my_subdir) : 在根文件夹中创建.htaccess文件,并将此内容放入其中(只需更改example.com和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. 在那里,您还可以通过更改常规设置中的URL找到执行此操作的说明,这也需要您复制.htaccess和index.php,然后再编辑它。 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: 使用您的WordPress核心文件的目录名称,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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