Mobile app version of vmapp.org
Login or Join
Barnes591

: Is the redirect problem a server aliasing problem or a .htaccess problem This past weekend, I ran into a redirect problem I have never seen before. BACKGROUND: the site is a static site that

@Barnes591

Posted in: #301Redirect #Htaccess

This past weekend, I ran into a redirect problem I have never seen before.

BACKGROUND: the site is a static site that was created by the site owner in a small, remote town. She figured out HTML and CSS amazingly well, but the file structure and CSS are poorly organized. So, my main task in helping her is to reorganize both while improving SEO. As I create a directory structure and move pages into the directories, I am adding 301 redirects to the .htaccess file. Then I test that the redirect works before removing the original file from the server.

ACTION: The first file move was to create a folder for a series of information pages about different minerals and rocks. These pages are not mission critical and made a good test. The first step was to create a directory called MineralFinder with a file called MineralFinderHome.html. The original file was at the root level and called minfind.htm.

BEHAVIOR: The first redirect line worked just fine. The second - fourth lines were

Redirect 301 /aluminum example.com/MineralFinder/Aluminum Redirect 301 /aluminum/aluminum.htm example.com/MineralFinder/Aluminum/Aluminum.html Redirect 301 /aluminum/process.htm example.com/MineralFinder/Aluminum/HowAluminumIsProcessed.html

These caused a URL not found error:



as shown in the image. The weird thing is that it is referencing the old file name without the camel case, but keeping the new directory structure with the camel case.

TECH SUPPORT: Tech support basically said they don't know why it's a problem and to use CPanel redirects. I'm not satisfied with that answer and want to know the cause of the behavior.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Barnes591

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

Redirect 301 /aluminum ....
Redirect 301 /aluminum/aluminum.htm ....
Redirect 301 /aluminum/process.htm ....



The mod_alias Redirect directive is prefix matching, so the first directive here will catch both /aluminum/aluminum.htm and /aluminum/process.htm. AND everything after the match is appended onto the end of the target URL.

So, given a request for /aluminum/aluminum.htm. This matches the first directive, and /aluminum.htm (the URL-path after the match) is appended onto the target example.com/MineralFinder/Aluminum which results in the URL in your screenshot, ie. example.com/MineralFinder/Aluminum/aluminum.htm.
The solution is to reverse these directives so the more specific directives are first.

You will need to clear your browser cache before testing, as the earlier 301 will be cached hard by the browser. (It is often safer to test with a temporary 302 redirect as this avoids the browser cache.)



Or, use RedirectMatch which matches against a regex and is not prefix matching. For example:

RedirectMatch 301 ^/aluminum$ example.com/MineralFinder/Aluminum

With the start and end anchors (^ and $ respectively) this only matches a request for /aluminum and not /aluminum/aluminum.htm.


Tech support basically said ... to use CPanel redirects.


If you are happy editing .htaccess files then I would avoid using "cPanel redirects". If you have other directives in .htaccess then I would advise against using "cPanel redirects". And if you need to do anything slightly more complex then... you can't use "cPanel redirects". (Btw, "cPanel" simply edits the .htaccess file when it implements a redirect, but it doesn't always get it right.)

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme