-2

I am setting 404 (400.php) and 400 (400.php) pages.

Website is https://www.rsseosolution.com

If i am typing https://www.rsseosolution.com/sdfsdfsdfsadfsda its working fine and showing 404.php page

But if i am trying to check any not existing php file like https://www.rsseosolution.com/monthly-link-building-campaign.php then its showing normal "File not found." message not redirecting to 404.php.

And for 400 error its showing normal server "Bad Request Error" While i want to show my custom 400.php.

Htaccess is as below

Options +FollowSymLinks
RewriteEngine on
# ensure www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule seo-package-(.*)-n-(.*)\.php$ seo-package-detail.php?id=$1&name=$2 [L]
RewriteRule case-studies/(.*)-(.*)\.php$ case-studies.php?project=$1&id=$2 [L]
RewriteRule tutorial/(.*)-(.*)\.php$ tutorial.php?topic=$1&id=$2 [L]
RewriteRule blog-page-(.*)\.php$ blog.php?page=$1 [L]
RewriteRule seo-tutorial-(.*)\.php$ seo-tutorial.php?page=$1 [L]
RewriteRule frequently-ask-question-faq-(.*)\.php$ frequently-ask-question-faq.php?page=$1 [L]
ErrorDocument 404 /404.php
ErrorDocument 400 /400.php

One more thing if i am adding [L] with 404.php and 400.php then server is giving "Internal Server Error" for complete site.

I want to redirect all URL (Page, blog and any other mistyping url) go to 404.php.

For bad request Error like https://www.rsseosolution.com/search/save%2050%%20seo%20budget should go to 400.php ....... Both pages are already on site and working fine if type manually page name.

Please guide me.

  • _Redirecting_ to `/404.php` is the wrong thing to do in the first place. Your server should answer with a 404 in response to the originally requested URL, not redirect elsewhere - that hinders clients like search engine bots from correctly recognizing that this was a 404 in the first place. – 04FS Sep 19 '19 at 11:58
  • I added `Options +FollowSymLinks RewriteEngine on ErrorDocument 404 https://www.rsseosolution.com/404.php` working fine for mydomain.com/asdfsd but if i type mydomain.com/asdfsd.php its showing normal text "File not found". Means without extension going to 404.php but with extension "File not Found" ..... Not getting exactly what is error. – Suraj Anjaana Sep 19 '19 at 12:04
  • One more thing its working fine on localhost but on server its showing this issue. Is there any issue with https (SSL)??? – Suraj Anjaana Sep 19 '19 at 12:08
  • I would not call this “working fine”, as long as it still causes an external redirect. (Which will happen, as long as you specify an absolute URL, instead of a local URL path.) // On your 400 bad request example URL, it says “nginx” in the output, so you don’t seem to be dealing purely with an Apache here, but appear to have some sort of proxy setup. If nginx already decides something is a “bad request”, then you can not specify what error to display using Apache config - it doesn’t even get that far. – 04FS Sep 19 '19 at 12:38
  • Thanks ...... Yes now its working fine. – Suraj Anjaana Sep 19 '19 at 13:49

1 Answers1

0

Try ErrorDocument 404 https://www.rsseosolution.com/404.php Using the full link (absolute URLs)

and write this rule in top of htaccess where you start writing rules

This link also have good explanation

Amanjot Kaur
  • 2,028
  • 4
  • 18
  • 33
  • `Options +FollowSymLinks RewriteEngine on # ensure www. RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # ensure https RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] ErrorDocument 404 https://www.rsseosolution.com/404.php ErrorDocument 400 https://www.rsseosolution.com/400.php RewriteRule seo-package-(.*)-n-(.*)\.php$ seo-package-detail.php?id=$1&name=$2 [L]` But still https://www.rsseosolution.com/sdafsdaf working but domain.com/adas.php not. – Suraj Anjaana Sep 19 '19 at 11:22