Ошибка 500 редирект

I am trying to make 500, 404, etc. errors redirect. If you go to http://www.yoursite.com/934834984 it should redirect to http://www.yoursite.com/404. How do I make it do that? I tried using this code:

<meta http-equiv="refresh" content="0; url=http://yoursite.com/404" />

Keep in mind that I changed the domain to yoursite.com just for this question.

Raptor's user avatar

Raptor

52.9k44 gold badges225 silver badges361 bronze badges

asked Jan 25, 2014 at 4:05

7

In Apache you can use ErrorDocument. So in your .htaccess file in the root of your domain you can add this to the end of the file.

ErrorDocument 404 /404.html

The files have to exist. Here is some more info as well.

http://support.hostgator.com/articles/custom-error-pages

answered Jan 25, 2014 at 4:09

Panama Jack's user avatar

Panama JackPanama Jack

24k10 gold badges63 silver badges95 bronze badges

7

You need to edit the .htacess file (with notepad) in your domain’s root folder. Here are some common ones that you would add or change in the file. Obviously change the directory and locations (the part in italics). And don’t include the numbers. Or you can change them from your cpanel without having to mess with the .htacess file

  1. ErrorDocument 400 /errors/badrequest.html
  2. ErrorDocument 401 /errors/authreqd.html
  3. ErrorDocument 403 /errors/forbid.html
  4. ErrorDocument 404 /errors/notfound.html
  5. ErrorDocument 500 /errors/server.html

answered Jan 25, 2014 at 19:18

adigioia's user avatar

adigioiaadigioia

1,1689 silver badges10 bronze badges

ErrorDocument 500 /errors/server.html not work for me

show in browser HTTP ERROR 500

answered Jan 14, 2019 at 17:41

Leonardo Inhoqui's user avatar

Today I’m attempting to redirect

Http://www.motorcyclemonster.com/MyMRa/

to

Http://www.mymra.com/

The problem is I can’t add anything without getting a 500 Internal Server Error. I can’t even add a regular redirect without getting the dreadful 500 internal server error.

Supposedly there’s a error file, however I can’t find it.

Anyone have any idea why this problem might occur?

Htaccess file:

http://pastebin.com/7EQxZFCx

Sent to pastebin for simplicity reasons.

Ram's user avatar

Ram

143k16 gold badges167 silver badges197 bronze badges

asked May 3, 2013 at 20:37

Sriahciboon's user avatar

5

That file is too big for me to sift through. Perhaps you could do a binary search, deleting parts of the file until it works. Then, as soon as you’ve narrowed it down, paste that portion.

answered May 3, 2013 at 20:41

mbarlocker's user avatar

mbarlockermbarlocker

1,30010 silver badges16 bronze badges

5

Аргументы разделяются пробелами. Redirect принимает максимум 3 аргумента, а из-за лишнего пробела их 4.

Redirect 301 /опалубка-колонн / https://site.su/category/prodazha-opalubki/prodazha-opalubki-kolonn/
Redirect 301 /опалубка-колонн/  https://site.su/category/prodazha-opalubki/prodazha-opalubki-kolonn/

Если пробел там действительно нужен, то можно добавить кавычки.

Redirect 301 "/опалубка-колонн /"  https://site.su/category/prodazha-opalubki/prodazha-opalubki-kolonn/

Redirect 301 keyboardchart.php keyboard-chart.php

The 500 error is because the target URL is relative. That is not allowed with a mod_alias Redirect. The target URL must either be absolute (with a scheme and hostname) or must start with a slash (ie. root-relative).

But also, the source URL-path will not match either. You must specify a root-relative URL-path, starting with a slash.

Regardless of where the .htaccess file is located, the mod_alias Redirect directive is the same. Unlike mod_rewrite (RewriteRule) that has the concept of a «directory-prefix».

So, like VladShundalov suggests, you would need a directive of the form:

Redirect 301 /keyboard/keyboardchart.php /keyboard/keyboard-chart.php

Note that this matches any query string. The query string is automatically passed through to the target. You can’t actually match the query string with a mod_alias Redirect.

If you need to match the specific query string then you must use mod_rewrite instead. For example, in the example.com/keyboard/.htaccess file you could write something like:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^gam=7&sty=15&lay=1$
RewriteRule ^keyboardchart.php$ /keyboard/keyboard-chart.php [R=301,L]

Note that you don’t state the subdirectory on the RewriteRule pattern in this case, however, you do still need a root-relative path on the substitution (unless you specify the path with a RewriteBase directive). The query string is passed through to the substitution automatically by default.

Yes, there is a rewrite loop for every URI coming from a subdomain here that doesn’t map to a filename or directory.

For example if the client comes in with mail.indst.eu/nofile

  • Hit subdomain rule mail.indst.eu for condition !^/mail -> rewrite to mail.indst.eu/mail/nofile
  • No longer matches !^/mail, doesn’t hit any external redirect rules, so falls through towards the end.
    • Doesn’t match the rewrite exclusion for existing files or one of the hardcoded exclusions
    • Hits the non-host-bound all-uri rule, gets rewritten to mail.indst.eu/index.php
  • Now it matches again the subdomain rule mail.indst.eu for condition !^/mail -> rewrite to mail.indst.eu/mail/index.php
  • No longer matches !^/mail, doesn’t hit any external redirect rules, so falls through towards the end.
  • Hits the non-host-bound all-uri rule, apparently mail/index.php is not an existing file, so /mail/index.php gets rewritten to /index.php, now we are in an alternating repeat between /index.php and /mail/index.php

/nofile
/mail/nofile (does not exist)
/index.php
/mail/index.php (does not exist)
/index.php
/mail/index.php (does not exist)
...repeat last two...

If you place an index.php in the subdirectories used by the subdomains, then a non-existing file uri on a subdomain will end up at the matching subdomain/index.php files, which for some applications may be what you want.
If you want a serverlevel 404 response, then you have to exclude the subdomain hosts from the catchall rewrite to index.php.

For example

RewriteCond %{HTTP_HOST} !^mail.indst.eu$
RewriteCond %{HTTP_HOST} !^www.statesanalytics.com$
RewriteRule ^.*$ index.php [NC,L]

OR, which might be more succint, and allow more subdomains:

RewriteCond %{REQUEST_URI} !^/mail
RewriteCond %{REQUEST_URI} !^/sa
RewriteRule ^.*$ index.php [NC,L]

Then a non existing uri at mail.indst.eu/starting-path is server level non existing if it doesn’t exist in mail/starting-path

There are other techniques to prevent such loops. If you know that there would always at most be one internal redirect for example, and all rewriterules reside in this one .htaccess then you can do this as first rewriterule in your .htaccess:

RewriteCond %{ENV:REDIRECT_STATUS} !^$
RewriteRule ^(.*)$ - [L]

That stops further internal redirects from this .htaccess. But it would require you to put the external redirect rules that you have before the internal redirect rules. It would not stop the RedirectMatch rules.

Or, if you know that a catchall rewrite to index.php should always be the last word the end mod_rewrite processing with [END]. But in this case that would mean a 404 on the subdomain ends up with the main directory index.php which may not be what you want.

RewriteRule ^.*$ index.php [END]

Понравилась статья? Поделить с друзьями:
  • Ошибка 500 при установке плагина wordpress
  • Ошибка 500 при установке битрикс
  • Ошибка 500 при установке joomla
  • Ошибка 500 при пост запросе
  • Ошибка 500 при попытке оплаты