0

I have a problem with my subdomain. When I try to enter a faulty page in the url it redirects me to index.php file in the directory. Which is blank, so the server cannot say me "Page not found" because it is finding a page which is index.php (blank page) what i did is that i added in the index.php to redirect me to the 404 page but i don't think that is the right solution.

https://docs.example.com/faultypage. -> redirect to https://docs.example.com/404page.html The .htaccess file in my docs directory have this data

   # GZIP compression for text files: HTML, CSS, JS, Text, XML, fonts
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
</IfModule>

And this is my docs.conf file

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName docs.example.com
    ServerAlias docs.example.com
    DocumentRoot /var/www/brand/Documentation/new



RewriteEngine on
RewriteCond %{SERVER_NAME} =docs.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
2
  • Hi guys fixed the internal error by creating a index.php file in the root directory of the subdomain. But now how to make it to show me error 404 page not found. When i enter faulty content in the url it redirects me to the index.php file...
    – AZAZEL
    Oct 31 at 10:12
  • Read the error long to get the reason for the 500 error. Them fix it instead of creating hacky workarounds. Oct 31 at 13:01

2 Answers 2

1

Add this in your faultypage directory .htaccess.

RewriteEngine On
RewriteRule ^index\.php$ /404.html [R=301,L]

Note :- Run following command if rewrite module is not enabled.

a2enmod rewrite
0

It is likely that your 404.html page is, itself, generating another 404 because the location is not /404.html, but /myweb/404.html. Basically it tries to find the 404.html file, but can't, which generates another 404, then tries to find the 404.html file, but can't, which generates another 404 etc etc. Change your .htaccess to point the 404 to /myweb/404.html, or move the file to the root of your server

4
  • For the loop I fixed it by adding blank index.php file in the directory, but now when i enter faulty url it is showing me the index.php and not the 404.html file, I added ErrorDocument 404 404.html but i think that this is not valid because everytime i write faulty url it opens me the index.php (basically there is no faulty page)
    – AZAZEL
    Oct 31 at 10:52
  • you need to configure the apache to look for 404.html whenever apache is unable to find the index.php file. If the index.php is present the apache loads the index.php because the apache first searches for index file. Oct 31 at 11:14
  • Check this link resolve your issue digitalocean.com/community/tutorials/… Oct 31 at 11:17
  • ErrorDocument 404 /404.html RewriteEngine on RewriteCond %{SERVER_NAME} =docs.example.com RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ /404.html [L] . Did this to the docs.conf file and nothing changed..
    – AZAZEL
    Oct 31 at 11:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .