【问题标题】:Remove subfolder name from WordPress site using htaccess使用 htaccess 从 WordPress 站点中删除子文件夹名称
【发布时间】:2016-09-17 16:57:15
【问题描述】:

我已将 WordPress 移至名为 /site 的子文件夹中,但 URL 现在显示为 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]

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

【问题讨论】:

    标签: php wordpress .htaccess url-rewriting


    【解决方案1】:

    我建议您不要弄乱 .htaccess 文件的内容。恢复您对此文件所做的更改并按照简单的程序进行操作。

    1. 登录到管理仪表板。
    2. 转到设置 > 常规
    3. 在 WordPress 地址 (URL) 字段中输入 http://www.example.com/site
    4. 在站点地址 (URL) 字段中键入 http://www.example.com

    保存更改,您应该一切顺利。

    【讨论】:

    • 谢谢,有时它不起作用并且服务器崩溃,但这是正确的技巧。
    • 尽管如果整个 WordPress 安装,包括 WP .htaccess 文件已被移动到子目录中,那么您将需要在文档根目录中添加一个额外的 .htaccess 文件,以便在内部将请求重写为那个子目录。 ,如果 WP .htaccess 文件保留在文档根目录中(即尚未移动到 WP 子目录),则需要修改 .htaccess 文件以将 WP 子目录包含在重写的 URL(WP 前端控制器) - 类似于问题中显示的内容。
    【解决方案2】:

    根据 Codex 中的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,然后最后进行编辑。第一种方法似乎更容易。

    【讨论】:

      【解决方案3】:

      尝试以下步骤:-

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

      【讨论】:

        猜你喜欢
        • 2014-04-13
        • 2016-04-13
        • 1970-01-01
        • 2015-08-02
        • 1970-01-01
        • 2013-09-29
        • 2017-02-17
        • 1970-01-01
        相关资源
        最近更新 更多