Website being directed to <domain>/blog for some reason

huangapple go评论95阅读模式
英文:

Website being directed to <domain>/blog for some reason

问题

我设置了apache2服务器。以下内容位于/etc/apache2/sites-enabled/default-ssl.conf文件中。

<IfModule mod_ssl.c>
        <VirtualHost _default_:443>
                ServerAdmin webmaster@localhost
                DocumentRoot /var/www/html
...

如果我访问https://www.example.com/index.html,它会按预期显示/var/www/html/index.html文件的内容。然而,如果我只访问https://www.example.com,它会重定向到https://www.example.com/blog。我无法在/etc/apache2目录中找到包含"blog"的任何内容。
我尝试过在/var/www/html中放置一个wordpress "blog"文件夹,并在mysql中有一个"blog"数据库。但我真的没有让它正常工作,并尝试放弃它。现在似乎我被困在这里,无法弄清楚它是如何启用的。我还注意到,如果我访问http://www.example.com(而不是https),它不会重定向到/blog,而是显示index.html的内容。
如果有人能解释apache2是如何决定将https://www.example.com重定向到https://www.example.com/blog,我会非常感激。谢谢。

英文:

I set up apache2 server. The following is in /etc/apache2/sites-enabled/default-ssl.conf.

&lt;IfModule mod_ssl.c&gt;
        &lt;VirtualHost _default_:443&gt;
                ServerAdmin webmaster@localhost
                DocumentRoot /var/www/html
...

<br>
If I visit https://www.example.com/index.html it displays the content of /var/www/html/index.html file as expected. However, if I just visit https://www.example.com, it redirects to https://www.example.com/blog. I can't find anything in /etc/apache2 directory that contains "blog" at all.
<br>I did try to put a wordpress "blog" folder inside /var/www/html before and have a "blog" database in mysql. But I didn't really get it to work and tried to abandon it. Now it appears I am stuck with it and I can't figure out where it is enabled. I also noticed, if I visit http://www.example.com (not https) it doesn't redirect to /blog but displays index.html content.
<br>Appreciate if anyone can explain how/why apache2 decides to redirect https://www.example.com to https://www.example.com/blog. Thanks.

答案1

得分: 1

登陆到你的WordPress仪表盘,然后进入设置,然后选择常规。那里会有两个条目:WordPress地址和站点地址。其中一个或两者可能会将“https://www.example.com/blog”作为值。更新这些URL,并在页面底部点击“保存更改”。

然而,如果你无法访问WordPress仪表盘,你将不得不查看数据库。检查你的WordPress数据库,特别是“wp_options”表;表名可能根据前缀而异,但“wp_”是默认值。在其中,有两个条目告诉WordPress站点托管在哪里。以下是你可以运行以查看其内容的MySQL查询:

SELECT * FROM wp_options WHERE option_name IN ('home', 'siteurl');

你可以使用以下查询更新这些字段:

UPDATE wp_options SET option_value = 'https://www.example.com/' WHERE option_name IN ('home', 'siteurl') LIMIT 2;

“home”(WordPress地址)与“siteurl”(站点地址)条目之间的区别在于,“home”条目是你的站点可访问的位置,“siteurl”是站点内容位于的URL(DocumentRoot)。根据你的情况,你的“home”将包含“/blog”,而你的“siteurl”将包含正确的URL。这是有关“siteurl”条目的WordPress文档

至于http与https之间的区别,这将取决于你的sites-available配置,但你也可以通过你的.htaccess文件以及“home”和“siteurl” URL条目来强制使用https。

编辑:作为快速修复,你还可以更新你的wp-config.php文件以更新相应的条目,但更好的、永久性的解决方案是使用WordPress仪表盘(或手动更新数据库的相同字段)。

英文:

Login to your WordPress Dashboard, and go to Settings, then General. There will be two entries: WordPress Address and Site Address. It's likely that one or both entries will have "https://www.example.com/blog" as the value. Update these URLs and click on Save Changes at the bottom of the page.

However, if you cannot access the WordPress Dashboard, you'll have to review the database. Check your WordPress database, specifically the "wp_options" table; name varies by prefix, but "wp_" is default. In it, there are 2 entries which tell the WordPress site where it is hosted. Here is the MySQL query you can run to see what it says:

SELECT * FROM wp_options WHERE option_name IN (&#39;home&#39;, &#39;siteurl&#39;);

You can update the fields with this query:

UPDATE wp_options SET option_value = &#39;https://www.example.com/&#39; WHERE option_name IN (&#39;home&#39;, &#39;siteurl&#39;) LIMIT 2;

The home (WordPress Address) vs siteurl (Site Address) entries differ in that the home entry is where your site can be reached, and siteurl is the URL of where the site content is located (DocumentRoot). Given your situation, it would appear that your home will have "/blog" and your siteurl will have the correct URL. Here is the WordPress documentation regarding the siteurl entry.

As for http vs https, that would depend on your sites-available configuration, but you can also force https with your .htaccess file, and both home and siteurl URL entries.

EDIT: as a quick fix, you can also update your wp-config.php file for the respective entries, but the better, permanent solution is to use the WordPress Dashboard (or manually updating the database for the same fields).

huangapple
  • 本文由 发表于 2023年2月6日 05:45:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75355735.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定