WordPress hyperlinks point to the wrong site level

Stock photo of computer code on a screen illustrating the problem of WordPress hyperlinks pointing to the wrong site level
Stock photo by Markus Spiske / Unsplash

Do you find yourself saying this after migrating your WordPress site: “After uploading my site from MAMP, where it worked fine, my WordPress hyperlinks point to the wrong site level”?

For example, let’s list the details of the problem:

  • your WordPress site is in a subfolder such as gwd.ca/students/billy-poppins/
  • You built your navigation using WordPress’s builtin menu manager (not hard coded in a template)
  • You have URLs such as gwd.ca/students/billy-poppins/about
  • The link now points to the wrong site level gwd.ca/about

.htaccess is the culprit

If this situation applies to you, the issue is that the Apache web server configuration file .htaccess was not updated properly during the migration process. This may be because of an error in the migration plugin itself, or a configuration error of the backup that was made in order to be migrate the site.

Origin of the problem

The core of the issue is that when you develop your web site using a software such as MAMP or Bitnami, you normally put the files directly inside htdocs. In other words, you place the files in the root folder of the site.

However, if you migrate your site to a different folder (something other than the root folder), then all of WordPress’s settings must be updated accordingly. In this particular case the .htaccess file is out of sync.

What does the .htaccess do anyway?

In WordPress, the .htaccess file can be used to do many things. But by default, one of the first things it does is remove the .php file extension from the URLs. It is this setting that is causing our problem.

Fixing WordPress hyperlinks that point to the wrong level

Option #1

In WordPress, go to Settings > Permalinks and click the Save button. This should automatically update the .htaccess file.

Option #2

Using your FTP program, login to the web server and select the .htaccess for editing. For example, in FileZilla, right-click on the file and select “View/Edit”. make the following changes to the file:

Before

RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

After

Note the text in bold is the correct path to your subfolder on the web server.

RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /current-grads/billy-poppins/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /current-grads/billy-poppins/index.php [L]
</IfModule>

If you have any question or comments, please drop them in the comments section below.

Author: Eric Girouard

Eric Girouard is a photography and design teacher in the Graphic & Web Design department, which he joined in 2001. He holds a BFA in Fine Art specializing in Drawing & Painting from Concordia University. His stock images were distributed worldwide by Corbis. Eric also worked at Trey Ratcliff’s “The Arcanum – Magical Academy of Artistic Mastery” and served as a photo contest judge for Viewbug.com.

Leave a Reply