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

时间:2016-05-20 12:13:13

标签: php wordpress .htaccess url-rewriting

我已将WordPress移至名为/site的子文件夹,但网址现在显示为http://www.example.com/site。我希望它在没有/site/子目录的情况下显示。

这是我当前的.htaccess代码

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

如何从可见网址中删除物理子目录?

3 个答案:

答案 0 :(得分:2)

我建议你不要弄乱.htaccess文件的内容。还原您对此文件所做的更改,并按照简单的步骤进行操作。

  1. 登录管理信息中心。
  2. 转到设置>一般
  3. 在WordPress地址(URL)字段中输入http://www.example.com/site
  4. 在网站地址(网址)字段中输入http://www.example.com
  5. 保存更改,你应该很高兴。

答案 1 :(得分:1)

根据食典委的Giving WordPress Its Own Directory,这就是你所需要的(对我有用)。

在根文件夹中创建一个.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>

在那里,您还可以通过更改常规设置中的URL来找到执行此操作的说明,这也需要您复制.htaccess和index.php,然后再编辑它。第一种方法似乎更容易。

答案 2 :(得分:0)

请尝试以下步骤: -

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

以下内容,使用您的WordPress核心文件的目录名:

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