• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Apache hide extension

hac3ru

Active Member


Messages: 109

#1
Hello,

I am running FreeBSD 9.2 with Apache2.4 and php5.5.1. I want to transform /hostaname/main.php into /hostname/main... I was able to do this on some Ubuntu but on FreeBSD I can't get it to work. Anyone can help me out?
 

Chris_H

Aspiring Daemon

Thanks: 111
Messages: 829

#2
Hmmm. That's odd. I don't have that problem, myself. I get exactly the same results that you're looking for, on all of my servers. Did you examine the difference(s) between the httpd.conf() (http://www.freebsd.org/cgi/man.cgi?....0-RELEASE+and+Ports&arch=default&format=html
files from both installs? Do you have the relevant additions for PHP within the mime_module section of httpd.conf? Have you added the MultiViews option to the Options section for the hostname/domain in question, in the httpd.conf?

HTH

--Chris
 

Chris_H

Aspiring Daemon

Thanks: 111
Messages: 829

#4
hac3ru said:
As far as I can see, the httpd.conf is correct... I added MultiViews option with no success...
OK. Assuming a nearly bone stock httpd.conf, and NO includes (separate virtual-host.conf files). I assume you have
Code:
#***************************************************************
# PHP -- include index.php as part of your DirectoryIndex.
# add the following to your Apache configuration file:

AddType application/x-httpd-php .php
AddType application/x-httpd-php .phtml
AddType application/x-httpd-php .inc
AddType application/x-httpd-php-source .phps
or the likes, within the <IfModule mime_module> section. Yes?
Now, assuming a virtual-host, which inherits from the main-server section, doesn't contain, among other options
Code:
Options MultiViews
You will need to use the following syntax, to add MultiViews
Code:
Options +MultiViews
note the addition of the +, in the above. It is also important to insure that the AllowOverride stanza doesn't prevent you from using Options MultiViews. Either from within the Main-Server section, nor within the Virtual-Host itself.
Lastly, the log file(s) are your friend. Apache will happily inform you of any issues it has, either with your config options/choices, or, regarding client requests to the Apache server, itself. So, assuming <domain-name>/main.php exists. What do the logs reveal, when you attempt to put http://<domain-name>/main in the URL bar of your web client (browser)?
Lastly, assuming that you add these to your .conf files. You will be required to re-start the server, to load the/any changes.

--Chris
 

hac3ru

Active Member


Messages: 109

#5
I did not have
Code:
AddType application/x-httpd-php .phtml
AddType application/x-httpd-php .inc
I have in all my virtual hosts the [/code] Options -Indexes +FollowSymLinks +MultiViews[/code]
I have added the AddType and I restarted the server. It is not working. When I check the logs for errors I see:
Code:
[08/Apr/2014:00:56:46 +0300] "GET /index HTTP/1.1" 404 202
In the /usr/local/etc/apache24/mime.types I have:
Code:
 application/x-httpd-php                         phtml pht php
application/x-httpd-php-source                  phps
application/x-httpd-php3                        php3
application/x-httpd-php3-preprocessed           php3p
application/x-httpd-php4                        php4
application/x-httpd-php5                        php5
 

Chris_H

Aspiring Daemon

Thanks: 111
Messages: 829

#6
hac3ru said:
I have in all my virtual hosts the
Code:
 Options -Indexes +FollowSymLinks +MultiViews
THIS is the problem.
See the error?
Code:
[08/Apr/2014:00:56:46 +0300] "GET /index HTTP/1.1" 404 202
You say
Code:
-Indexes
Yet, you attempt to load /index. As your log entry:
Code:
[08/Apr/2014:00:56:46 +0300] "GET /index HTTP/1.1" 404 202
indicates.

To fix this, change
Code:
-Indexes
to
Code:
+Indexes
Problem solved. :)

--Chris
 

hac3ru

Active Member


Messages: 109

#7
I'll try it tomorrow but indexes is used to list the files inside a directory that doesn't have an index.php file. Don't think it will solve it. Will try it tomorrow
 

Chris_H

Aspiring Daemon

Thanks: 111
Messages: 829

#8
hac3ru said:
I'll try it tomorrow but indexes is used to list the files inside a directory that doesn't have an index.php file. Don't think it will solve it. Will try it tomorrow
Yes, in part. But given you specifically asked for index, as the log indicated. You will have to at least have a file called index. Or why bother to ask for index?
You know you can also define Indexes, on a per-directory basis. For example:
Code:
/usr/local/www/somefolder
<IfModule dir_module>
	DirectoryIndex rubbish RUBBISH trash.php garbage.html nopage.xhtml poo.garbage
</IfModule>
Then, when choosing http://<my-domain>/someplace Apache will look for all the files listed within DirectoryIndex, and serve up the first one it finds, as the Index, if no other file was requested.
Getting a feel for how it works?

--Chris
 

hac3ru

Active Member


Messages: 109

#9
As I was saying, adding +Indexes did nothing. The only thing that changed is that now if the specified index pages are not present (which for me is just index.html and index.php) it will list the files in the directory....
The error occurs no matter what I try to load. I tried to load index because I was sure that there was an index.php page there. If I try to access localhost/index it will give me a 404 - Page not found. If I access localhost/index.php it is working. Same thing for http://localhost/admin and http://localhost/admin.php. When the .php is specified, the page is loaded correctly. If it is not specified, it returns Page not found.
 

Chris_H

Aspiring Daemon

Thanks: 111
Messages: 829

#10
OK. I've got a clearer picture of what you're getting at. Sorry.
Try adding the following:
Code:
RewriteEngine on
just beneath the Options stanza under the
Code:
<Directory ...
and see if that gives you your desired results. You can change +Indexes to -Indexes. :)

--Chris
 

hac3ru

Active Member


Messages: 109

#11
Code:
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
Is what I get when I run service apache24 restart
Nevermind. I loaded the mod_rewrite.so module and the error went away. Still, calling
Code:
http://localhost/admin
returns 404.
 

Chris_H

Aspiring Daemon

Thanks: 111
Messages: 829

#12
OK. Perhaps I've made too many assumptions here.
Does the following line exist under <IfModule mime_module>?
Code:
TypesConfig etc/apache22/mime.types
Under <Directory "/usr/local/www/working-path">
Code:
Options -Indexes +Includes +FollowSymLinks +SymLinksifOwnerMatch +ExecCGI +MultiViews
Do you also have the following, under it?
Code:
MultiviewsMatch Handlers Filters
If not. Try and see if that get's you where you want to be. In an effort to keep this simple. I created an additional virtual-host, with only those stanzas, and get exactly what you're looking for.

--Chris
 

hac3ru

Active Member


Messages: 109

#13
Chris_H said:
OK. Perhaps I've made too many assumptions here.
Does the following line exist under <IfModule mime_module>?
Code:
TypesConfig etc/apache22/mime.types
Under <Directory "/usr/local/www/working-path">
Code:
Options -Indexes +Includes +FollowSymLinks +SymLinksifOwnerMatch +ExecCGI +MultiViews
Do you also have the following, under it?
Code:
MultiviewsMatch Handlers Filters
If not. Try and see if that get's you where you want to be. In an effort to keep this simple. I created an additional virtual-host, with only those stanzas, and get exactly what you're looking for.

--Chris
I have
Code:
TypesConfig etc/apache24/mime.types
but shouldn't it be
Code:
/usr/local/etc/apache24/mime.types
I also now have:
Code:
    Options -Indexes +Includes +FollowSymLinks +SymLinksifOwnerMatch +ExecCGI +$
    MultiViewsMatch Handlers Filters
Still not working......
 

Chris_H

Aspiring Daemon

Thanks: 111
Messages: 829

#14
hac3ru said:
Chris_H said:
OK. Perhaps I've made too many assumptions here.
---8<---[snip]
I have
Code:
TypesConfig etc/apache24/mime.types
but shouldn't it be
Code:
/usr/local/etc/apache24/mime.types
Well, if you're working from a "stock" build/install. Directories can usually be managed relative to the ServerRoot;
Code:
ServerRoot "/usr/local"
So that actually makes etc/apache24/mime.types: /user/local/etc/apache24/mime.types. No?
hac3ru said:
I also now have:
Code:
    Options -Indexes +Includes +FollowSymLinks +SymLinksifOwnerMatch +ExecCGI +$
    MultiViewsMatch Handlers Filters
Still not working......?
Odd. You are restarting (not reloading) the server, after making these changes. Right?
Another thought; did you build Apache out of the ports tree? Or did you use pkg(8) system to install it?

--Chris
 

hac3ru

Active Member


Messages: 109

#15
Yeah, you're right. I am using
Code:
ServerRoot "/usr/local"
Yes, I am restarting the apache24 server using service apache24 restart

If I remember it correctly, I have installed it via the ports tree.
 

Chris_H

Aspiring Daemon

Thanks: 111
Messages: 829

#16
hac3ru said:
Yeah, you're right. I am using
Code:
ServerRoot "/usr/local"
Yes, I am restarting the apache24 server using service apache24 restart

If I remember it correctly, I have installed it via the ports tree.
OK. Unless you've done something out of the ordinary with the rest of your server config. We'll have to look a different direction. But a last note before we do; Assuming you have index.html, and footer.html in the root of your server. If you put http://yourserver/index, or http://yourserver/footer, in the URL bar of your browser. Do you still get a 404? Something also worth noting; you should keep your logs within your editor, so that you can monitor the request(s) being made, as they're being made. This will help you better determine what the/any cause is for experiences you expect, but aren't getting. It'll also help you determine whether your browser is caching the responses -- something you should check. In other words; it's quite possible you're not getting current answers, to current questions. Catch my drift? :) Please note; that when I speak of the requests to index, or footer, above. I talking html, not PHP. That's important. I also assume, you're using a reasonably smart editor, that checks the files status it has open, on a reasonably frequent basis, and alerts you to those changes.

--Chris
 

hac3ru

Active Member


Messages: 109

#17
It doesn't work with test.html. I created a test.html file and I accessed http://localhost/test and it returned: 404 Not found.

In the logs, I have the time of the entry and it is current time. It's not caching, it's the current request.
I also did tail -f /var/log/http-access_log and I can see the request and the 404 returned to the browser.
 

Chris_H

Aspiring Daemon

Thanks: 111
Messages: 829

#18
hac3ru said:
It doesn't work with test.html. I created a test.html file and I accessed http://localhost/test and it returned: 404 Not found.

In the logs, I have the time of the entry and it is current time. It's not caching, it's the current request.
I also did tail -f /var/log/http-access_log and I can see the request and the 404 returned to the browser.
OK. Here's a "last ditch effort". Add the following lines just above the AllowOverride stanza
Code:
# DO NOT ADD THE NEXT LINE UNTIL YOU HAVE TRIED THE FOLLOWING ONE FIRST
AddOutputFilter Includes html xhtml
# TRY THE FOLLOWING ONE ALONE, BEFORE ADDING THE LINE ABOVE
AddHandler type-map var
# In other words, add the one line above. But comment (#) the other
following the instructions above. Add both lines, but comment the first one. Then restart the server. See if that'll get it. If not, also add the other one, as well (uncomment it). then restart, and see what you get.

--Chris
 

Chris_H

Aspiring Daemon

Thanks: 111
Messages: 829

#20
hac3ru said:
Still not working :(
If I uninstall apache and make a clean install you think I'll have some more luck? :)
At this point. Given all the messing around with it. I think that's probably a wise move.
DO delete, or move all of the MODIFIED stuff out of the way, be performing a make deinstall, and make config, make install clean. For example; move www to www_old. You can also simply delete all the etc/apache24/* stuff. That way, you can be sure that you actually ARE getting a nice new fresh install. :)
Lemme know when you've finished the install, but before you start, or edit anything. :)

--Chris
 

hac3ru

Active Member


Messages: 109

#21
Okay so I deinstalled apache24, deleted /usr/local/etc/apache24 folder and I have moved /usr/local/www/ to my home folder. Installing apache now. I need the php module loaded and mysqli + hiding extension for php. What should I modify?
 

Chris_H

Aspiring Daemon

Thanks: 111
Messages: 829

#22
hac3ru said:
Okay so I deinstalled apache24, deleted /usr/local/etc/apache24 folder and I have moved /usr/local/www/ to my home folder. Installing apache now. I need the php module loaded and mysqli + hiding extension for php. What should I modify?
Forgot about PHP. You'll probably need to deinstall the PHP module before you deinstall www/apache2*. But, as long as you don't also deinstall PHP (no point, really), the mysql, and mysql lib for PHP, should not be an issue (don't worry about them). :)

--Chris
 

Chris_H

Aspiring Daemon

Thanks: 111
Messages: 829

#23
I guess, when your done. The best plan should be to copy etc/apache2(2|4)/httpd.conf to etc/apache2(2|4)/httpd.conf.ORG, and etc/apache2(2|4)/extra/httpd-default.conf to etc/apache2(2|4)/extra/httpd-default.conf.ORG. That way, you'll have virgin copies to roll back to, in the future. Should you ever have to. This gives you (us) free reign, to do whatever. Without concern. I gotta tell you tho. I've been doing this for ~20yrs, and manage some 120 domains, with even more hosts, and this one's been really odd.

OK. Then, lemme know when yer ready. I'll be in, and out. But, will keep an eye on the thread. :)

--Chris
 

hac3ru

Active Member


Messages: 109

#24
I did backed up those files because I had to use the server the night that just passed. I backed up the configs and I have edited the settings so that people will be able to use the server this 12hours+.

I did not deinstall php module. Do you think that it will be a problem?
 

Chris_H

Aspiring Daemon

Thanks: 111
Messages: 829

#25
hac3ru said:
I did backed up those files because I had to use the server the night that just passed. I backed up the configs and I have edited the settings so that people will be able to use the server this 12hours+.
Sure. Understood. Good thinking. :)
hac3ru said:
I did not deinstall php module. Do you think that it will be a problem?
Probably not an issue. Have you tested php(1), to see if it works with Apache, as expected? Maybe something like creating the file phpinfo.php in the root of your server, containing:
Code:
<?php
phpinfo();
?>
then following the link: http://yourserver/phpinfo.php, or better; http://yourserver/phpinfo -- assuming there is no longer a need to provide the extension. :)

--Chris