Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > .htaccess Redirect in "Sites" not redirecting: why?

.htaccess Redirect in "Sites" not redirecting: why?
Thread Tools
Mac Enthusiast
Join Date: Oct 2001
Location: Chicago, IL
Status: Offline
Reply With Quote
Jan 16, 2002, 10:53 PM
 
Hey hey,
I dropped an .htaccess file in my "Users/bdash/Sites" folder with the following:

Redirect /Sites /Sites/boulderpages/index.html

That way people wouldn't be able to see my directory listings when they hit http://127.0.0.1/~bdash. But... it's not working. I restarted Apache with the following:

sudo apachectl graceful

I don't kow if I need to restart Apache or not, but I do every time I reconfigure the .htaccess file to see if it will work. Do I need to do something to the "bdash.conf" in order for this to work? Is the syntax wrong in my ".htacces" file or something? Does ".htaccess" need some particular Permissions settings to work?

Thanks in advance,
Boulder
     
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Jan 17, 2002, 06:24 AM
 
Have you got the 'AllowOverride' set to 'None' in the Apache config? That wouldn't help. It would mean that Apache would ignore your .htaccess file.

But do you need to set the .htaccess for that to work? All you need to do is add '-indexes' to your 'options' directive in the <directory> option and that should fix that.
Computer thez nohhh...
     
Mac Enthusiast
Join Date: Oct 2001
Location: Chicago, IL
Status: Offline
Reply With Quote
Jan 17, 2002, 12:04 PM
 
Still not working (even after re-starting Apache),
Here's my "/etc/httpd/users/bdash.conf" file:

<Directory "/Users/bdash/Sites/">
Options -Indexes MultiViews FollowSymLinks
AllowOverride
Order allow,deny
Allow from all
</Directory>


Here's me "Users/bdash/Sites/.htaccess"file:

Redirect /Sites http://www.yahoo.com/


Yahoo, is for testing purposes of course. So why is this not doing anything do you think?

Thanks,
Boulder
     
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Jan 17, 2002, 04:57 PM
 
Originally posted by BoulderDash:
<STRONG>Still not working (even after re-starting Apache),
Here's my "/etc/httpd/users/bdash.conf" file:

&lt;Directory "/Users/bdash/Sites/"&gt;
Options -Indexes MultiViews FollowSymLinks
AllowOverride
Order allow,deny
Allow from all
&lt;/Directory&gt;


Here's me "Users/bdash/Sites/.htaccess"file:

Redirect /Sites http://www.yahoo.com/


Yahoo, is for testing purposes of course. So why is this not doing anything do you think?

Thanks,
Boulder</STRONG>
I think it should read 'AllowOverride All'.

Even so, if you had a file called 'index.html' then it would stop users being able to browse your directory anyway - is there a particular reason you wanted to do it this way?

[ 01-17-2002: Message edited by: Simon Mundy ]
Computer thez nohhh...
     
Mac Enthusiast
Join Date: Oct 2001
Location: Chicago, IL
Status: Offline
Reply With Quote
Jan 17, 2002, 06:00 PM
 
Well,
This is just a start in learning how to do Redirects (and apparently a slow one). BTW, adding "All" after "AllowOverride" and re-starting Apache didn't do anything... does it work on your server?

Thank,
Boulder
     
Senior User
Join Date: Sep 2000
Location: Shallow Alto, CA
Status: Offline
Reply With Quote
Jan 17, 2002, 07:34 PM
 
I'm pretty sure you need mod_alias compiled in apache in order to use the redirect command. I don't know if the apache in osx has mos_alias installed.

I went round and round with my ISP trying to get this implemented correctly and ended up using a PHP solution instead. Searching the web for how to setup redirects in apache I learned that it is one of those things that doesn't go smoothly quite often, but YMMV.

Anyway if you can say what you're trying to accomplish then there may be easier, more reliable ways to do it.
     
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status: Offline
Reply With Quote
Jan 20, 2002, 02:20 AM
 
Originally posted by BoulderDash:
<STRONG>
Redirect /Sites /Sites/boulderpages/index.html
</STRONG>
Try:

Redirect temp /index.html http://www.apple.com/index.html

If that doesn't work, try adding:

DirectoryIndex index.html
     
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
Jan 20, 2002, 03:32 PM
 
The "/Users/*/Sites/" folders have their own individual config files at "/etc/httpd/users/", you need to change the settings there.
     
Mac Enthusiast
Join Date: Oct 2001
Location: Chicago, IL
Status: Offline
Reply With Quote
Jan 20, 2002, 08:11 PM
 
Still *NOT* working (even after re-starting Apache),
Here's my "/etc/httpd/users/bdash.conf" file now:

&lt;Directory "/Users/bdash/Sites/"&gt;
Options Indexes MultiViews FollowSymLinks
DirectoryIndex index.html
AllowOverride All
Order allow,deny
Allow from all
&lt;/Directory&gt;


Here's me "Users/bdash/Sites/.htaccess"file:

Redirect temp /index.html http://www.yahoo.com/


Can anyone get re-directs to work?

Thanks,
Boulder
     
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status: Offline
Reply With Quote
Jan 22, 2002, 02:19 PM
 
Originally posted by BoulderDash:
<STRONG>Can anyone get re-directs to work?
</STRONG>
Hmmm... it's not working for me either. I'm going to keep working on this to try to figure it out. As far as i can tell, there are three files involved (listed in order of dominance):

/etc/httpd/httpd.conf
/etc/httpd/users/account_name.conf
/Users/account_name/Sites/.htaccess

Where "account_name" is the name of the user account you're using.

I can't find anything in the default httpd.conf which might preclude redirects. I did find this:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>#
# This controls which options the .htaccess files in directories can
# override. Can also be <font color = red>"All"</font>, or any combination of <font color = red>"Options"</font>, <font color = red>"FileInfo"</font>,
# <font color = red>"AuthConfig"</font>, and <font color = red>"Limit"</font>
#
AllowOverride None
</font>[/code]
but changing None to All didn't seem to make a difference. And there's this:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>#
# Each directory to which Apache has access, can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the <font color = red>"default"</font> to be a very restrictive set of
# permissions.
#
&lt;Directory /&gt;
Options FollowSymLinks
AllowOverride None
&lt;/Directory&gt;

#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#
</font>[/code]
Which seems to be what we want... assuming we turn it on later in /etc/httpd/users/account_name.conf
for the directories we want to enable .htaccess (if i understand correctly how this is supposed to be done). And that should look something like this:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>&lt;Directory <font color = red>"/Users/account_name/Sites/"</font>&gt;
AllowOverride all
&lt;/Directory&gt;
</font>[/code]

although all is overkill and FileInfowould probably suffice. But in as much as i am uncertain of this, i test with all.

I even checked with the Apache website to verify which module the Redirect command is in, just to make sure it's enabled in httpd.conf. As i read it, it is in mod_alias, which appears to be enabled in httpd.conf:<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>LoadModule alias_module libexec/httpd/mod_alias.so
AddModule mod_alias.c </font>[/code]

So given all this, it looks to me that this should be working, but it's not. Obviously, we're overlooking something here.

I think you can also place redirects directly in the /etc/httpd/users/account_name.conf file, so i placed a redirect in mine to test it out (figuring that's one less link in this chain of files), but still wasn't able to get it working. We've got to be close. I can't imagine others not wanting to use redirects, so surely someone must know the answer to this! I'm thinking the problem lies somewhere before the .htaccess file.
     
Mac Enthusiast
Join Date: Oct 2001
Location: Chicago, IL
Status: Offline
Reply With Quote
Jan 23, 2002, 10:06 PM
 
Well,
I can't say that I have any idea why this doesn't work. I've tried everything that I've read about... but that's about all I can do. I really don't know that much about Apache - and what I've seen work on other servers doesn't work on the Mac OSX installation.

Anyone else have any idea? Rainy? Thanks.
     
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Jan 24, 2002, 04:37 PM
 
Originally posted by BoulderDash:
<STRONG>Well,
I can't say that I have any idea why this doesn't work. I've tried everything that I've read about... but that's about all I can do. I really don't know that much about Apache - and what I've seen work on other servers doesn't work on the Mac OSX installation.

Anyone else have any idea? Rainy? Thanks.</STRONG>
Hokay... try the links here or here.

Are these any good for you?

BTW, Check the permissions on your .htaccess file to make sure they are executable... I'd hate to think that was the problem after such a long time in testing!


[ 01-24-2002: Message edited by: Simon Mundy ]
Computer thez nohhh...
     
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Jan 24, 2002, 06:19 PM
 
Oops. Double post

[ 01-24-2002: Message edited by: Simon Mundy ]
Computer thez nohhh...
     
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Jan 24, 2002, 06:21 PM
 
OK, so I've had a half hour to check your problem out.

I've got it to work (hurrah!)

This is what I did:

Used the terminal to do the following (replace ~username with yours):

cd /Users/~username/Sites
sudo pico .htaccess

Redirect permanent / http://www.apple.com/index.html

Then saved and closed pico. Now just a quick matter of setting permissions:

sudo chmod 755 .htaccess

Done! I guess I didn't really need to create and own the file by root, guess it's force of habit.

Then I opened up the config file again:

sudo pico /etc/httpd/users/~username.conf

Changed 'AllowOverride' to 'All'.

Test. Works!

One problem, though. When it redirected to Apple's site, it tacked on the '~username' to the end of the URL, which made the page fail. I guess this is something to do with mod_rewrite or something? I'll do a bit more digging to see what can be done about that...

Bye for now!

[ 01-24-2002: Message edited by: Simon Mundy ]
Computer thez nohhh...
     
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status: Offline
Reply With Quote
Jan 25, 2002, 12:20 AM
 
Originally posted by BoulderDash:
<STRONG>Well,
I can't say that I have any idea why this doesn't work. I've tried everything that I've read about... but that's about all I can do. I really don't know that much about Apache - and what I've seen work on other servers doesn't work on the Mac OSX installation.

Anyone else have any idea? Rainy? Thanks.</STRONG>
Okay, i finally got it to work.

First, my .htaccess wasn't working. Turns out the problem with the .htaccess file was this: Before i began editing my user configuration file /etc/httpd/users/account_name.conf, i made a backup of it in the same folder: /etc/httpd/users/account_name.conf.bak. I hadn't realized that Apache reads every file in that directory when parsing its configuration file.

Since my backup file was the last configuration file to load, its original AllowOverride none directive overrode any AllowOverride all in either the user configuration file i was editing, or in the main Apache configuration file (which i tried as well). This prevented my .htaccess file from firing up. Once i moved the backup file to another directory, .htaccess started working. Okay, step one complete.

Also, i should mention that the correct place to change the AllowOverride directive is not in the main Apache configuration file /etc/httpd/httpd.conf, but in a user configuration file /etc/httpd/users/account_name.conf (as that is exactly the kind of thing for which user configuration files are intended). Apache needs to be restarted once any of the .conf files are edited, but not when an .htaccess file is changed. Oh, and you need to use linefeeds rather than returns as line endings in all of these files (i.e. the UNIX way, not the Mac way).

By the way, the appropriate Apache module for redirects (mod_alias) is enabled by default under MacOS X, so no worries there.

The next thing is to get the redirect line correct. If you want to redirect the file located at /Users/account_name/Sites/index.html to, say /Users/account_name/Sites/crackers.html, you'd use a redirect like this:
Redirect temp /~account_name/index.html http://localhost/~account_name/crackers.html
But if you'd rather redirect to another site, you might do something like this:
Redirect temp /~account_name/index.html http://www.apple.com/
Of course <font color = red>account_name</font> should be replace by your user account name.

By the way, you should also be able to include redirects in your user configuration file, and that might be preferable to .htaccess as the latter is parsed when the page is being loaded, whereas the former is parsed when Apache starts up (i.e. it's a speed boost).

Of course, as someone else has already pointed out, redirects are not the best way to keep someone from viewing your directories. For that, you should include an:

Options -indexes
Okay, hope this clears things up.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:48 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2