Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.htaccess n00b 1

Status
Not open for further replies.

Supra

Programmer
Dec 6, 2000
422
US
Hey folks, what I've done is used .htaccess in my root folder to specify the following:
Code:
DirectoryIndex index.pl
ErrorDocument 403 [URL unfurl="true"]http://www.something.com/error.pl?403[/URL]
ErrorDocument 404 [URL unfurl="true"]http://www.something.com/error.pl?404[/URL]
ErrorDocument 500 [URL unfurl="true"]http://www.something.com/error.pl?500[/URL]
Options -Indexes
This works fine, however I want a particular folder to redirect to a different URL on error 404. I've placed a .htaccess file in that folder and changed the URL for ErrorDocument 404 accordingly, however it still redirects to the old URL. On the other hand, I may not even be setting this up correctly for what I want to do. Basically, I want a folder to act like Wikipedia's do. That is, if a user types in , I would like the script index.pl inside the states folder to use pennsylvania as a variable and not a folder. I assume that you could pass the entire 404 path to a script (../states/index.pl) and just slice off the missing "folder" from the end to use as a variable in your script. Is this correct or does assuming really make an ass of u and me :|
 
Hi Feherke,

yes the other directives work, however they are the same URL's as specified in the .htaccess file in the root folder. That is, the .htaccess in the root folder looks like this..
Code:
DirectoryIndex index.pl
ErrorDocument 403 [URL unfurl="true"]http://www.something.com/error.pl?403[/URL]
ErrorDocument 404 [URL unfurl="true"]http://www.something.com/error.pl?404[/URL]
ErrorDocument 500 [URL unfurl="true"]http://www.something.com/error.pl?500[/URL]
Options -Indexes
..and the .htaccess in the "states" folder looks like this:
Code:
ErrorDocument 403 [URL unfurl="true"]http://www.something.com/error.pl?403[/URL]
ErrorDocument 404 [URL unfurl="true"]http://www.something.com/states/viewState.pl[/URL]
ErrorDocument 500 [URL unfurl="true"]http://www.something.com/error.pl?500[/URL]
So the only line I've actually changed is the 404 error document. Do changes in the .htaccess file take effect immediately? I believe they took effect within 5 minutes after I set them up in the root folder.
 
Hi

There is no reason to repeat the same directives in the .htaccess too. I mean for 403 and 500. Is better to keep .htaccess as short as possible, because it is parsed before each request and could slow down the Apache.

To find out if it is working properly, put this line into that .htaccess file. That must make Apache to answer 403 Forbidden to all requests.
Code:
Deny from all
Then share your experience with us to advice further steps.

Feherke.
 
Well I just checked the page again before I made the changes and it works. I guess it just needed a few hours to take effect. Thanks a ton for the information though, because I didn't think about the loss of speed due to parsing each line in the .htaccess file. I removed every line except the one that differs from the .htaccess file in the root folder. Thanks again!
 
Well now I have a new issue ;) In my first post I said I wanted the script (the one redirected to from a 404 error) to work like Wikipedia in that it will slice off the end of the URL that was typed in and use it as a variable. I thought I could achieve this by using $ENV{'HTTP_REFERER'}, however this is not the case. Is there some way to send the invalid URL to the error document?
 
I figured it out. For those like me who didn't know, if you want the REDIRECT_URL (The URL you are redirecting from) environment variable to be sent to the URL you are redirecting to, your error document path must NOT be a remote location and/or include Even if your website is you may not use as your error document if you want to use environment variables.

Anyway, thanks again for all the help Feherke!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top