View Full Version : .htaccess redirect question
05-11-2011, 07:09 AM
I'm hoping this august group can help me. There is a forum post article out there on the interwebs that links to one of the posts on my site. Unfortunately the author of that post botched the link so that instead of:
Consequently the link 404s. I've attempted several variations of a simple 301 redirect in my .htaccess file, however none have worked. I suspect I may need a workaround for the "<br />" in the link.
Any ideas on how best to setup this redirect in .htaccess?
08-05-2011, 09:39 AM
No love huh? Alright then I went ahead and figured it out me-own-self. Hopefully this will help some of you other ne'er-do-wells.
RedirectPermanent "/2009/09/how-to-dual-<br />boot-windows-7-and-linux-using-bcdedit/"
08-05-2011, 11:30 AM
I recommend using a symbolic link, rather than an htaccess redirect for this particular instance, unless you're expecting multiple broken links and need to match a pattern.
The reason being, if you use an htaccess file, every time someone tries to access anything the server will check to see if it should redirect it. Since you only want to correct a single path, it doesn't make sense to call this for every request.
The performance impact is minimal so it isn't really necessary, it's just something to consider.
You can create a symlink (http://php.net/symlink) by creating a php file containing something like this, then calling it from your browser.
<?php echo (symlink('2009/09/how-to-dual-boot-windows-7-and-linux-using-bcdedit','2009/09/how-to-dual-<br />boot-windows-7-and-linux-using-bcdedit'))?"Symlink created successfully":"Failed to create symlink"; ?>
I don't know if I really got that path right, so if it doesn't work I probably just wouldn't bother with it. It's relative so it needs to be in your document root.
08-05-2011, 12:15 PM
Hmm... I hadn't considered a symlink. I have shell access, could I simply create one with something like this?
ln -s /2009/09/how-to-dual-boot-windows-7-and-linux-using-bcdedit /2009/09/how-to-dual-<br />boot-windows-7-and-linux-using-bcdedit
08-05-2011, 12:30 PM
Yeah you could do it through the shell, it's just not everyone has shell access. I'm not sure starting the path with a slash will get you what you want though, I think that might go all the way back to the system root.
I think your home directory is listed in the sidebar in cPanel under "Stats", so it ends up being like /home/username/2009/09/how-to-dual-boot-windows-7-and-linux-using-bcdedit for the absolute path.
08-05-2011, 12:39 PM
ah, k, something like this then?
ln -s /home2/me/public_html/2009/09/how-to-dual-boot-windows-7-and-linux-using-bcdedit /home2/me/public_html/2009/09/how-to-dual-<br />boot-windows-7-and-linux-using-bcdedit
08-05-2011, 12:46 PM
Right, public_html goes in there too. That looks correct to me.
08-05-2011, 01:00 PM
Thanks so much Basil. I'll give it a try and update the thread.
PS. Where were you two months ago ;-)
08-05-2011, 01:11 PM
I only check in every once in a while since I don't even have a bluehost account any more, but I try to answer questions to expand my own knowledge in various subject areas. If I don't know the answer to a question I'll usually look up how to do it so if I ever need to do it myself I'll know how.
My friend is telling me this won't actually work because the <> characters are for piping, and even if you escape them they can't be used in a directory path. So there goes that idea. Sorry about that.
Here's the apache manual on mod_rewrite (http://httpd.apache.org/docs/current/mod/mod_rewrite.html), you can skip down to RewriteRule for some examples. Obviously what you already have is working for you so I wouldn't mess with it, but it's there for future reference or if you want to get into it more.
08-05-2011, 01:35 PM
You're friend is right. I just tried it and there's no obvious way to build the link. Oh well, I did learn something so it wasn't a waste of time. Thanks again for your time and assistance on this Basil.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.