简体   繁体   English

链接打开404错误页面

[英]Link opens 404 error page

I'm having a problem with a WordPress link. 我的WordPress链接有问题。 I'm using php to link to my subpage called page-projekti.php with the following code: 我正在使用php通过以下代码链接到名为page-projekti.phppage-projekti.php

<?php echo site_url('/projekti/'); ?>

When I click the link, it opens up a 404 page, which says: 当我单击链接时,它将打开一个404页面,其中显示:

Object not found! 找不到对象!

The requested URL was not found on this server. 在此服务器上找不到请求的URL。 The link on the referring page seems to be wrong or outdated. 推荐页面上的链接似乎有误或已过时。 Please inform the author of that page about the error. 请将该错误告知该页面的作者。

If you think this is a server error, please contact the webmaster. 如果您认为这是服务器错误,请与网站管理员联系。

The link used to work just fine before I reinstalled WordPress due to some issues I had. 由于某些问题,在我重新安装WordPress之前,该链接曾经可以正常工作。 Now it just displays this page everytime I click on it. 现在,每当我单击它时,它就会显示此页面。

Did I change something important by accident, while reinstalling? 重新安装时是否偶然更改了重要的内容? Or is there another reason, why this does not work? 还是有另一个原因,为什么这不起作用?

In wordpress documentation it says: WordPress文档中,它说:

   echo site_url();

will return the url for the current site you are on, but through parameters you can get url´s to other pages. 会返回您当前所在网站的网址,但是通过参数您可以将网址转到其他页面。 The complete function is: 完整的功能是:

  site_url( $path, $scheme );

as an example they give: 作为示例,他们给出:

  $url = site_url( '/secrets/', 'https' );

so maybe you want to try also using that second parameter "$scheme", so try: 因此,也许您也想尝试使用第二个参数“ $ scheme”,所以请尝试:

  echo site_url('/projekti/', 'https);

or 要么

  echo site_url('/projekti/', 'http');

Also if your site is called "page-projekti" you might want to try: 另外,如果您的网站名为“ page-projekti”,则可能要尝试:

  echo site_url('/page-projekti/', 'https');

An other way to get a link to a page is, using the function: 获取页面链接的另一种方法是使用函数:

 echo get_page_link($page_id);

Every page gets an id you can use. 每个页面都有一个您可以使用的ID。 Here is a link, which explains how to get the id of a page: WordPress Page ID 这是一个链接,它说明了如何获取页面IDWordPress页面ID

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

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