wordpress如何做到在子目录安装而在根目录访问

根目录下可能有多个站点,此时就需要将wordpress文件放在一个子目录中,但是通过配置,可以在通过根目录来访问。

第一步:wamp5下根目录是www文件夹,在此文件夹中建立子目录文件夹,并将所有文件除了index.php都放入到子文件夹中

1

 

第二步:打开index.php文件,修改里面的代码
require('./wp-blog-header.php');
如改为:
require('./leeseoBlog/wp-blog-header.php');

2

第三步:到wordpress的安装后台,在常规设置中
在“WordPress 地址(URL)”处,将其修改为您的 WordPress 核心文件的新位置。例如:localhost/leeseoBlog

在“站点地址(URL)”一栏,保留您原来根目录的位置。如:localhost

3

点击“保存设置”。(别担心此时看到的错误消息,也不要现在进行测试!不然您大概会得到“文件未找到”之类的错误消息。)


附上英文文档

Giving WordPress Its Own Directory

Many people want WordPress to power their website's root (e.g. http://example.com) but they don't want all of the WordPress files cluttering up their root directory. WordPress allows you to install it into a subdirectory, but have your website served from the website root.

As of Version 3.5, Multisite users may use all of the functionality listed below. If you are running a version of WordPress older than 3.5, please update before installing a Multisite WordPress install on a subdirectory.

Note to theme/plugin developers: this will not separate your code from WordPress. Themes and plugins will still reside under wp-content folder.

Moving a Root install to its own directory

Let's say you've installed wordpress at `example.com`. Now you have two different methods to move wordpress installations into subdirectory: 1) Without change of SITE-URL (remains `example.com` 2) With change in SITE-URL (it will redirect to `example.com/subdirectory`)


Method I (Without URL change)

1) After Installing the wordpress in root folder, move EVERYTHING from root folder into subdirectory.

2) 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>

That's all :)

Method II (With URL change)

Moving process

(p.s. If you've already installed WP in subdirectory, some steps might be already done automatically).

  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 Screen.
  3. In WordPress address (URL): set the address of your main WordPress core files. Example: http://example.com/wordpress
  4. In Site address (URL): set root directory's URL. Example: http://example.com
  5. Click Save Changes. (Do not worry about the errors that happen now! Continue reading)
  6. Now move your WordPress core files (from root directory) to the subdirectory.
  7. 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.
  8. Open your root directory's index.php file in a text editor
  9. 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' );
  10. Login to the new location. It might now be http://example.com/wordpress/wp-admin/
  11. If you have set up Permalinks, go to the Permalinks Screen and update your Permalink structure. WordPress will automatically update your .htaccess file if it has the appropriate file permissions. If WordPress can't write to your .htaccess file, it will display the new rewrite rules to you, which you should manually copy into your .htaccess file (in the same directory as the main index.php file.)

.htaccess modification

In some cases, some people like to install separate versions in a subdirectory (such as /2010, /2011, /latest and etc..), and want that website (by default) used the latest version, then Install WordPress in a subdirectory, such as /my_subdir and in your root folder's .htaccess file add the following (just change the words as you need):

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ my_subdir[L]


Now when users go to your root domain (example.com), it will automatically redirect to the subdirectory you specified.

Note: This code comes from Site 5's post here: How to Redirect Your Domain to a Subfolder Using .htaccess.


Windows 上安装 WordPress 需要先搭建一个本地的 Web 服务器环境。以下是安装 WordPress 的步骤: 1. 下载并安装一个本地服务器软件,比如 XAMPP 或 WampServer。这些软件提供了 Apache 服务器、MySQL 数据库和 PHP 解释器,是运行 WordPress 所需的基本环境。 2. 安装完成后,启动服务器软件,并确保 Apache 和 MySQL 服务都已启动。 3. 打开你的 Web 浏览器,输入 "localhost" 或 "127.0.0.1",进入本地服务器的主页。 4. 在主页上找到并点击 phpMyAdmin,进入数据库管理界面。 5. 在 phpMyAdmin 中创建一个新的数据库,用于存储 WordPress 的数据。 6. 下载 WordPress 的最新版本,并解压到服务器的网站根目录(比如 XAMPP 中的 htdocs 目录或 WampServer 中的 www 目录)。 7. 打开解压后的 WordPress 文件夹,找到并复制 "wp-config-sample.php" 文件,并将其重命名为 "wp-config.php"。 8. 使用文本编辑器(比如 Notepad++)打开 wp-config.php 文件,并填写数据库相关信息(数据库名称、用户名、密码等)。 9. 保存并关闭 wp-config.php 文件。 10. 打开你的 Web 浏览器,输入 "localhost/wordpress"(如果你将 WordPress 解压到了网站根目录子目录 wordpress 中)或 "localhost"(如果将 WordPress 解压到了网站根目录),进入 WordPress 安装界面。 11. 按照界面上的指引,填写站点标题、用户名、密码等信息,并完成安装过程。 12. 安装完成后,你将可以通过输入 "localhost/wordpress" 或 "localhost" 访问你的 WordPress 网站,登录后即可开始使用。 这是在 Windows 上安装 WordPress 的一般步骤,具体细节可能因不同的服务器软件版本或个人需求而有所差异。建议参考官方文档或在线教程以获得更详细的指导。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值