404 Not Found; Apache Server can't load simple php file
Apache will route a request to a VirtualHost
that matches ServerName
or ServerAlias
first, or the one labeled _default_
or the first VirtualHost
defined if there isn't one. Based on that, serves whatever file was requested, from the DocumentRoot
directory for that VirtualHost
or the DirectoryIndex
defined if there is no file.
So, up to this point, given your (known) directory structure, you need the following configuration:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Users/antonio-pavicevac-ortiz/Sites/
<Directory "/Users/antonio-pavicevac-ortiz/Sites/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera/"
ServerName fragrances.christinaaguilera
ServerAlias www.fragrances.christinaaguilera
<Directory "/Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera/">
Options +Indexes +Includes +FollowSymLinks -MultiViews
AllowOverride None
DirectoryIndex rootfile.php
Require local
</Directory>
</VirtualHost>
Note that I changed the MultiViews
, AllowOverride
and DirectoryIndex
settings.
Now, when you access http://fragrances.christinaaguilera
Apache would normally try to serve index.html
or similar file, but with DirectoryIndex
will serve that file instead. With AllowOverride All
, it'll check for existence of .htaccess
and apply the rules in there but I've disabled it for now. We'll take it one step at a time.
You can check if apache is picking up your configuration by executing apachectl -D DUMP_VHOSTS
. It should show you the defined VirtualHosts
. If there is none, make sure your virtual host config file is being included in your main httpd.conf
server config by looking for Include
directives like:
Include /private/etc/apache2/extra/httpd-vhosts.conf
Include /private/etc/apache2/extra/*.conf
Make sure the path match and restart the service.
Once we get the VirtualHost
up and running it's time to get the .htaccess
. For that, we need to change AllowOverride
back and get rid of the DirectoryIndex
directive, leaving the Directory
for the VirtualHost
like this:
<Directory "/Users/antonio-pavicevac-ortiz/Sites/fragrances.christinaaguilera/">
Options +Indexes +Includes +FollowSymLinks -MultiViews
AllowOverride All
Require local
</Directory>
And now, we should see the same redirection behaviour when accessing the site. With a bit of luck, we'll see the site. If not, we'll begin by commenting out the line RewriteBase /restage
.
Most of the file should not be necessary for our purposes. I think we can get by with this minimal version to start:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /rootfile.php/$1 [L]
That's a quite standard clean url router setup. It translates to "redirect any request that is not a physical file or directory on disk to rootfile.php/uri".
Now try to access http://fragrances.christinaaguilera/en/
.
Here's a breakdown for the rest of the file:
The
AddType
directives tell apache to send mime headers for those specific file extensions. You might not need them if running a modern version of apache, but just to be sure...The
RewriteCond %{HTTP_HOST}
lines and followingRewriteRule
redirect to a canonical url (the www. version). Doesn't make much sense in development, unless it's to make sure there are no extra redirections.All the
RewriteRule hu/$ /en/ [R=301,L]
you shouldn't ever need, as it's handled on the php side (if(!in_array($language, $validLanguages))
). They redirect to the english version. Except for the/de/
one, that's still in use. Also leave thelang/home$
redirections in there, just to be safe.
Finally the three potentially problematic lines:
RewriteBase /restage/
RewriteCond %{REQUEST_URI} !microsite
RewriteRule ^(.*)v_([0-9]*)/(.*)$ /restage/$3 [L]
Can't say for sure what they do without more info in the internal links, but here is what they translate to:
RewriteBase
basically says "for any rewriting that occurs, prepend/restage/
to it". This is file wide, so it would affect therootfile.php
redirection too. So it should be a restage directory inside your project with (mostly) the same files for this rules to make sense.- The following two rules translate to "any request that is not a microsite and contains the string "v_" followed by numbers and a slash and any string, redirect to /restage/restage/any_string". There are two
/restages
in the translation because of theRewriteBase
. That behaviour is what worries me the most, but as I said, need more info on the project structure. Looks like someone was working on adding some features to a copy of the site.
PHP file always ends in 404 object not found
You redirect on the first line. Get rid of that! If you do need the redirection, add it at the end!
<?php
$handle = fopen("Project.html", "a");
foreach($_POST as $value ) {
fwrite ($handle, $value);
}
fclose($handle . "\n");
header("location: add/Project.html" );
PHP script not working. Receiving error 404. Web server DOES support PHP
That might happen, when you don't have the action page:
<form method="post" action="index.php">
You set the action page to index.php, so if that file doesn't exist or located somewhere else,
you might get a 404 error or Object not found.
Make sure you have index.php AND it exists in the same directory with your other files.
If you want to take the action on the page itself, then do:
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
localhost/~username is not working, gives 404 Not Found error
I am not sure what @jhilgeman is talking about. Apache has an extension for Per-user web directories that must be setup in order to map ~username to the home directory specified in the configuration. It looks like you have enabled the correct extension but missed the UserDir
directive.
For Example: UserDir public_html
will serve /home/myuser/public_html
at http://your.host.tld/~myuser/
For you example, ditch the <Directory>
and use the UserDir
directive instead. Please read over https://httpd.apache.org/docs/2.4/howto/public_html.html for setup instructions.
PHP code is not being executed, but the code shows in the browser source code
Sounds like there is something wrong with your configuration, here are a few things you can check:
Make sure that PHP is installed and running correctly. This may sound silly, but you never know. An easy way to check is to run
php -v
from a command line and see if returns version information or any errors.Make sure that the PHP module is listed and uncommented inside of your Apache's httpd.conf This should be something like
LoadModule php5_module "c:/php/php5apache2_2.dll"
in the file. Search forLoadModule php
, and make sure that there is no comment (;
) in front of it.Make sure that Apache's httpd.conf file has the PHP MIME type in it. This should be something like
AddType application/x-httpd-php .php
. This tells Apache to run.php
files as PHP. Search for AddType, and then make sure there is an entry for PHP, and that it is uncommented.Make sure your file has the
.php
extension on it, or whichever extension specified in the MIME definition in point #3, otherwise it will not be executed as PHP.Make sure you are not using short tags in the PHP file (
<?
), these are not enabled on all servers by default and their use is discouraged. Use<?php
instead (or enable short tags in your php.ini withshort_open_tag=On
if you have code that relies on them).Make sure you are accessing your file over your webserver using an URL like
http://localhost/file.php
not via local file accessfile://localhost/www/file.php
And lastly check the PHP manual for further setup tips.
404 Not Found The requested URL was not found on this server
In httpd.conf file you need to remove #
#LoadModule rewrite_module modules/mod_rewrite.so
after removing # line will look like this:
LoadModule rewrite_module modules/mod_rewrite.so
I am sure your issue will be solved...
CodeIgniter: 404 Page Not Found on Live Server
You are using MVC with OOPS Concept. So there are some certain rules.
1) Your class name (ie: controller name) should be start with capital Letter.
e.g.: your controller name is 'icecream'. that should be 'Icecream'
In localhost it might not be compulsory, but in server it will check all these rules, else it can't detect the right class name.
Related Topics
How to Get the Sucess Message in the Same Page After Submitting the Contact Form
Php to View Pdf on Web Page and Disable User to Download
Unset a Value in a Multi-Dimensional Array Based on One of the Values
Sum Value in Foreach Loop Every 3 Time Looping
Delete Digits After Two Decimal Points, Without Rounding the Value
Detect a Quotation in a String
How to Get the MAC and the Ip Address of a Connected Client in PHP
Executing Python Script in PHP and Exchanging Data Between the Two
Php Curl Required Only to Send and Not Wait for Response
How to Remove Back Slashes from Json Output in PHP
Warning: Mysqli_Connect(): (Hy000/1049): Unknown Database in MAC Terminal Only
[Php][Mysql] How to Insert Data in 2 Tables At Same Time
Check If Username and Email Already Exists in Database
How to Download an Mp3 File from Remote Url
Query With Multiple Values in a Column