justuptime.com - monitor your servers & websites

.htaccess

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.

He has: 44 posts

Joined: Dec 2003

I've been having alot of trouble with .htaccess at the moment. I have set up a site which I want to redirect any directories, apart from the ones i specify, to a file.

For example if someone was to type in site.com/hfhfrh it would redirect to a file but if they went to a directory i specify it would let them there (for example a folder called images).

How would I do this. I've tried Mod Rewrite but i can only make it redirect every directory even the ones i want not to redirect. Also when it redirects it redirects as if the file people are redirected to is in the directory they typed in. For example, the file might be in the root directory but if they went to a directory like 'spoons' the .htaccess file would redirect but as if the file was in the spoons folder.

Hopefully I explained well. If not i will try to explain more.

Busy's picture
Modrater

He has: 6,157 posts

Joined: May 2001

you could use mod rewrite so that no slash went to file and slash went to folder
site.com/hfhfrh <-- file
site.com/hfhfrh/ <-- folder

easier way is not to worry about rewriting the folders and just do the files, gets a bit tricky when you working at different levels thou.

If you give us a bit of code it might be easier to tune for you

<?bhb if(broken){ echo("It wasn't me Smiling "); } ?>
Learn HTML the ez way - EzHTML.net

Some people are like slinkies, they dont really serve any purpose but they still bring a smile to your face when you push them down the stairs ...

They have: 168 posts

Joined: Jan 2005

Can you tell us exactly what you want it to do? (IE: Make a .php?asd987a&hdasfu file into blah-blah.html file)

I'll quack like a penguin, and sting like a flee.
eGaming Supply MMORPG Services - MMORPG Marketplace

They have: 2 posts

Joined: Aug 2005

Why not use a 404 error page that redirects to the file you're talking about (if i'm correct on what you're trying to do)?

Greg K's picture
Moderator

He has: 1,667 posts

Joined: Nov 2003

From the way I have ready your post, I agree the 404 redirect would be what you want.

Now if you still want to have a different "404 error" for files off of your main site, you could do some checking to see what the really requested.

-Greg

[This space intentionally left blank]

Cool Geek Supplies: www.ThinkGeek.com

They have: 2 posts

Joined: Aug 2005

Actually, it appears (another theory) you would want to block Hot-Linking and the execution of the files within the folder you are talking about. If you'd provide us with the exact scenario of what you're trying to do, it'd help.

He has: 44 posts

Joined: Dec 2003

Thanks for the help but after a good few hours researching regular expressions I managed to figure out what to do. I needed it to make this: http://www.zurl.net

Greg K's picture
Moderator

He has: 1,667 posts

Joined: Nov 2003

yes, that is easy, we do that for affiliate links, do domain.com/textid and then let that redirect to the numeric one, so people could use more memorable urls.

We just set up the 404 page to check against a database (after a few checks to eliminate obvious not used ones). If it matched, it did a redirect to the other site after sending out the right headers. Otherwise it send the 404 headers and gave the error page.

-Greg

[This space intentionally left blank]

Cool Geek Supplies: www.ThinkGeek.com

timjpriebe's picture
DeveloperModeratorSponsor

He has: 2,666 posts

Joined: Dec 2004

Does anyone know of a good guide to all the different things you can do with .htaccess? Clean URLs, redirecting, error pages, interpreting html files as php, etc? I'm looking to do a bit more research into them and would love it if I could find one site with all the info I need.

Busy's picture
Modrater

He has: 6,157 posts

Joined: May 2001

I recently lost all my bookmarks but there is a site with the name htaccess or similar, was a while ago but believe that is good and also has links. Like most topics, not any one site lists everything. Also have to remember not all work on all servers with a little tweaking.

<?bhb if(broken){ echo("It wasn't me Smiling "); } ?>
Learn HTML the ez way - EzHTML.net

Some people are like slinkies, they dont really serve any purpose but they still bring a smile to your face when you push them down the stairs ...

He has: 4 posts

Joined: Jan 2006

This is a great article all about .htaccess file.

http://www.javascriptkit.com/howto/htaccess.shtml

The Ramen Years
All the things your counselor never told you about college.

http://theramenyears.com

timjpriebe's picture
DeveloperModeratorSponsor

He has: 2,666 posts

Joined: Dec 2004

Nice link. Thanks, theramen!

I also found this page, which gives more info on transparently rewriting URLs:

http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html