.htaccess
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.
Austers
Busy posted this at 20:14 — 8th January 2006.
He has: 6,151 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
EGS posted this at 04:32 — 9th January 2006.
They have: 161 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)
spiralfive posted this at 20:28 — 10th January 2006.
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 posted this at 20:32 — 10th January 2006.
He has: 2,145 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
spiralfive posted this at 21:02 — 10th January 2006.
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.
Austers posted this at 19:00 — 12th January 2006.
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
Austers
Zurl - Zurl your URL
Greg K posted this at 21:36 — 12th January 2006.
He has: 2,145 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
timjpriebe posted this at 13:54 — 13th January 2006.
He has: 2,667 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.
Tim
http://www.tandswebdesign.com
Busy posted this at 23:08 — 13th January 2006.
He has: 6,151 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.
theramen posted this at 08:44 — 18th January 2006.
He has: 4 posts
Joined: Jan 2006
This is a great article all about .htaccess file.
http://www.javascriptkit.com/howto/htaccess.shtml
timjpriebe posted this at 17:38 — 18th January 2006.
He has: 2,667 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
Tim
http://www.tandswebdesign.com
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.