Viewed   428 times

I have a .htaccess file in the root directory and also 404.php file there. Content of my .htaccess file is:

ErrorDocument 404 /404.php 

But when I am mis-spelling my url, 404.php is not opening. Instead I am getting following message:

Not Found

The requested URL /mywebsite/ites.php was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

But when I tried ErrorDocument 404 google.com, it worked.

 Answers

1

I'll consolidate my comments to this answer:

When setting ...

ErrorDocument 404 /404.php

the /404.php path may not be the absolute path to your htdocs folder root but instead the root of your filesystem. This may be, based on your configuration, e.g. /home/htdocs/ or ~ and so on.

So what one need to do is find out the absolute path and set it accordingly.

Saturday, September 3, 2022
 
tbm0115
 
5

You can try:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

## If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
## If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
## don't do anything
RewriteRule ^ - [L]

RewriteRule ^allstores/([^/]+)/?$ /allstores.php?ln=$1 [L,QSA,NC]

# To internally forward /foo to /foo.php
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]

RewriteCond %{QUERY_STRING} !^q=.+ [NC]
RewriteRule ^([^/]+)/?$ /store.php?st=$1 [L,QSA]
Friday, December 9, 2022
 
3

Your web server will server the HTML page as is. It will only parse the HTML as best as it can. If you rename your page with a PHP extension, the web server will parse it using the PHP interpreter and that is when PHP will be interpreted. Also as Fred points out in the comments you can tell Apache to treat HTML as PHP.

Wednesday, August 17, 2022
 
x2.
 
x2.
3

You could try something like this :

RewriteCond %{REQUEST_URI} !^/dir_under_rootdocument/index.php
RewriteCond %{REQUEST_URI} !.(gif|jpg|png|js|css)$
RewriteRule (.*) dir_under_rootdocument/index.php/$1 [L,QSA]
Wednesday, August 31, 2022
31

The last rule doesn't have any conditions, so it is used always.

RewriteRule ^.*$ autodiscover.php [NC,L]

The RewriteCond directive defines a rule condition. One or more RewriteCond can precede a RewriteRule directive. The following rule is then only used if both the current state of the URI matches its pattern, and if these conditions are met.

Therefore, all your conditions are related to the previous rule, instead:

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

Also:

  • You only need RewriteEngine On once.

  • Options- Autodiscover would have a syntax error IF there was such a server feature.

Sunday, December 18, 2022
 
g.m.
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :