1

I want to make a custom 301 page, not the usual apache one.

I added this to .htaccess

ErrorDocument 301 /301.php

I have made the "design" for this page, but how can I make it read the redirectmatch entries in .htaccess and use them? If that's not possible I could make something like if("$_SERVER[REQUEST_URI]" ==), etc. but it would take a very long time. Is there another way?

Edit: To clarify for anyone who didn't understand, I want to change the html code of the default 301 page, which currently looks like this for me:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="/index.php">here</a>.</p>
</body></html>

I have already made the custom one but I don't know how to make read from .htaccess what to redirect.

5
  • Are you trying to automatically redirect with a Location header (as most 301s do)? Commented Jan 30, 2016 at 2:58
  • Yeah, it's kind of confusing, because a 301 isn't an error. It's a permanent redirect. That means that you'll be sent to another page or site. Server error pages have status codes in the 400's and 500's (900's too for mobile communication).
    – Iwnnay
    Commented Jan 30, 2016 at 3:15
  • Are you getting any errors in accessing 301? I can't see why it wouldn't work.
    – Alex
    Commented Jan 30, 2016 at 3:15
  • @Alex, no, no errors but currently the page is just html code. I am wondering how to implement all the functions that the default 301 has. I know how to read the query and then redirect, but that would mean I would have to make a new if for everything I want to redirect, so instead I asked how I can make it read .htaccess and use it's functions like the default 301 page does. Commented Jan 30, 2016 at 3:26
  • Perhaps lwnnay is correct, and since 301 isn't an Error in itself it wouldn't behave like an error page at all. What it does instead is send an html 301 response code to the user behind the scenes. That would state that the intended page was redirected elsewhere.
    – Alex
    Commented Jan 30, 2016 at 3:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.