【问题标题】:Is it possible to change site address(site url) only on homepage of the WordPress Website?是否可以仅在 WordPress 网站的主页上更改站点地址(站点 url)?
【发布时间】:2020-05-13 15:41:45
【问题描述】:

我将 WordPress 安装到“wp”目录,现在每个页面的 url 如下所示

http://example.com/wp/
http://example.com/wp/access/
http://example.com/wp/contact/ ...

但我只想在主页上删除“wp”。 我想得到的结果如下

http://example.com/
http://example.com/wp/access/
http://example.com/wp/contact/ ...

如果我在站点路由上更改站点地址(url)设置和 index.php, 这会从所有页面中删除所有“wp”。

网站地址(url)

http://example.com/

站点路径上的index.php

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

我想知道是否可以只在主页上更改网站网址。

【问题讨论】:

    标签: php wordpress .htaccess redirect mod-rewrite


    【解决方案1】:

    您可以在 function.php 文件中添加以下页面并将http://yoursiteurl.com 替换为您的站点 URL

    function redirect_homepage() {
        if( ! is_home() && ! is_front_page() )
            return;
    
        wp_redirect( 'http://yoursiteurl.com', 301 );
        exit;
    }
    
    add_action( 'template_redirect', 'redirect_homepage' );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-30
      • 2015-03-03
      • 1970-01-01
      • 1970-01-01
      • 2011-11-19
      • 2017-04-14
      相关资源
      最近更新 更多