Htaccess 404 & 301

Htaccess 404 & 301 - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the Htaccess 404 & 301 error on your web browser. Problem :


The site runs on WordPress (latest) and is installed in /htdocs/www/.
This htaccess file is in /htdocs/www/roh/ along with a bunch of images and some CSS.



I want requests to the old html files to redirect to their new WordPress pages. I got most of it working, except the example below.



RewriteEngine On
RewriteBase /htdocs/www
ErrorDocument 404 /htdocs/www/
Redirect /roh/z1/q2lvl[1-9].html http://www.example.com/realms-of-hyrule/legend-of-zelda/maps


I go to www.example.com/roh/z1/q2lvl2.html, and it 404s and takes me to the main 404 page in my WordPress theme.



I tried ErrorDocument 404 /htdocs/www/roh/404.html, but that just got me an ISP redirected spam search page. The only way I got the main WordPress 404 page working was by going up directories until something worked. I do not want to send 404s to an http:// address.



My questions:




  1. Why doesn't the range of numbers [1-9] work?


  2. Why can't I get /htdocs/www/roh/404.html working for anything in /roh and below?




Sorry for the basic questions, not exactly sure what to search for, so Google is only giving me examples I've tried or have working already.


Solution :


  1. Use RedirectMatch directive instead. Redirect does strict string comparison while RedirectMatch uses regular expressions and therefore can be "dynamic".



    RedirectMatch 301 /roh/z1/q2lvl[1-9].html http://www.example.com/realms-of-hyrule/legend-of-zelda/maps


    BTW, if you are using Redirect and/or RedirectMatch directives only, then no need for RewriteEngine or RewriteBase (those are from 2 different modules).


  2. Not sure -- but maybe because RewriteRules from folder above come into play... Rewrite debugging usually can shed some light on what is going on (it can show which 404 file Apache is trying to use, as rewrite rules got applied to it as well).. but for that you have to be able to edit server config or virtual host config.



We hope that this article has helped you resolve the htaccess, redirects, 404 error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=