Jump to content
xisto Community
Mordent

Using .htaccess Locally?

Recommended Posts

Hi all!

It's been a while since I've posted on Xisto, but as always when a technical problem comes up this is the first place I turn to for answers. So, on to my issue:

I'm running Fedora Core 10 (64-bit) on my machine, with the classic Apache/MySQL/PHP package build. I'll admit that I needed a little help from this site to get it working well (though note that I didn't do the firewall malarky on there, as I found a nicer way of getting it to work that currently eludes me as to how I found it), but it's generally working absolutely fine.

The one issue I have is in using .htaccess. Assuming an entirely default setup for Apache (I can quote relevant sections of phpinfo if needed), is it just my understanding of how .htaccess works that's flawed, or something else entirely?

I'm trying to perform some simple error handling (404, 500, etc.) using a .htaccess file in the root directory of the website in question (/var/www/html/mywebsite/) as below:

ErrorDocument 403 /index.php?page=forbiddenErrorDocument 404 /index.php?page=not_foundErrorDocument 500 /index.php?page=server_error
Given that I'm performing the relevant checks in the index.php page (i.e. using $_GET) is there any reason why I can't use this approach? If not, why is it that when I type "localhost/mywebsite/test.html" in to my web browser (and yes, clearly Apache is running, though I have made that mistake before :o) I get the standard error?

Not Found
The requested URL /mywebsite/test.html was not found on this server.

Any help or pointers towards pages that might be helpful would be appreciated, as I can't see any reason for it not to be working. Thanks in advance!

Share this post


Link to post
Share on other sites

Did you first check that, with a standard index.html file in (/var/www/html/mywebsite/index.html) you see something when you point your browser to "localhost/mywebsite/" ?

Share this post


Link to post
Share on other sites

Yup. As I said, the rest of the website's working absolutely fine. It prints HTML, parses PHP, accesses the MySQL database etc. with no problems, I just can't seem to get .htaccess to work. Odd, huh?

 

EDIT: So, after trawling cyberspace for the answer, I found it (or at least the start to it). Seems the default installation for Apache doesn't allow overrides. One tweak of that later and .htaccess works like a charm...that is when SELinux is disabled. Damn, I hate that thing...I don't suppose anyone knows a way to stop SELinux from blocking Apache from using the .htaccess files, or perhaps some other workaround?

 

EDIT: After some more rummaging around, I've drawn a blank. I'm tempted just to disable SELinux, as it's being more of a pain than anything, but as a last attempt to get something working I figure I might as well show you the errors I'm getting:

 

Summary

SELinux is preventing the httpd from using potentially mislabeled files (./.htaccess).

Detailed Description

SELinux has denied httpd access to potentially mislabeled file(s) (./.htaccess). This means that SELinux will not allow httpd to use these files. It is common for users to edit files in their home directory or tmp directories and then move (mv) them to system directories. The problem is that the files end up with the wrong file context which confined applications are not allowed to access.

Allowing Access

If you want httpd to access this files, you need to relabel them using restorecon -v './.htaccess'. You might want to relabel the entire directory using restorecon -R -v '.'.

Additional Information

Source Context:  system_u:system_r:httpd_t:s0

Target Context:  unconfined_u:object_r:user_home_t:s0

Target Objects:  ./.htaccess [ file ]

Source:  httpd

Source Path:  /usr/sbin/httpd

Port:  <Unknown>

Host:  steve

Source RPM Packages:  httpd-2.2.11-2.fc10

Target RPM Packages:  

Policy RPM:  selinux-policy-3.5.13-59.fc10

Selinux Enabled:  True

Policy Type:  targeted

MLS Enabled:  True

Enforcing Mode:  Enforcing

Plugin Name:  home_tmp_bad_labels

Host Name:  steve

Platform:  Linux steve 2.6.27.21-170.2.56.fc10.x86_64 #1 SMP Mon Mar 23 23:08:10 EDT 2009 x86_64 x86_64

Alert Count:  9

First Seen:  Thu 21 May 2009 16:19:04 BST

Last Seen:  Thu 21 May 2009 16:44:42 BST

Local ID:  d2abe2b4-5b42-485d-81c6-d3e9578d91a1


EDIT: And, as per usual, I've been a complete dunce. I did what it told me to do, and it now works like a charm!
Edited by Mordent (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.