Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo
- - - - -

How To Use The .htaccess File To Redirect Users


  • Please log in to reply
1 reply to this topic

#1 nosnhoj#3

nosnhoj#3

  • Members
  • 245 posts
  • OFFLINE
  •  
  • Location:127.0.0.1
  • Local time:03:00 AM

Posted 23 June 2006 - 08:52 PM

How To Use The .htaccess File To Redirect Users




Guide Overview

The purpose of this guide is to teach you how to use the .htaccess file to redirect users to pages that you have modified, deleted, or moved. The .htaccess file is associated with Apache Servers. Not all web hosting services allow modification of this file. Before following this guide, contact your web hosting service provider to confirm that addition and/or modification to this file is allowed.


Instructions
  • Access your site using the method you normally use to implement changes, and determine whether or not your directory includes a file named .htaccess
  • If it does, open the file in the text editor of choice. (If so, Skip to step 5)
  • If it does not, you will need to create one, and upload it to the Root Directory of your site. To do this, open up Notepad or your preferred text editor.
  • Click File ---> Save as...
    In Notepad, change the Save as type to All Files. Give your file the name .htaccess (the period "." before htaccess is required) and save it to the directory of your choice. Close the file.
  • Now, open the .htaccess file with the text editor of your choice, and in one complete line, enter the commands for your desired effect, with a space between each command:

    The redirect command has the following format: redirect status /old/old.html http://www.new.com/new.html
    - "Status" is optional and may be one of the following:

    permanent or 301 resource has moved permanently.
    temp or 302 resource has moved temporarily.
    seeother or 303 resource has been replaced.
    gone or 410 resource has been permanently removed. (When this status is used the new-url argument should not be used.)

  • Save the file, and depending on if it previously existed in the web directory or if you created it, update your site.

    NOTE: If you created the file, it is important that you upload the file to the Root Directory of your site, which is the directory where your default "index" or "home" page resides.

Redirection Notables

1. Be sure not to add "http://www" to the first part of the statement - just put the path from the top level of your site to the page. Also ensure that you leave a single space between these elements:

redirect 301 (the instruction that the page has moved)

/old/old.html (the original folder path and file name)

http://www.new.com/new.html (new path and file name)

2. Each page being redirected needs to occupy it's own line in the .htaccess file.

Conclusion

Be sure to test out your changes after you make them. If something does not work as intended, delete the entry, so it does not create any further problems, and refer to your web host for answers.
When I'm right, I'm right....
And when I'm wrong, I could have been right....
So I'm still right, cause I could have been wrong.

BC AdBot (Login to Remove)

 


#2 Wendy K. Walker

Wendy K. Walker

  • Members
  • 633 posts
  • OFFLINE
  •  
  • Gender:Female
  • Location:In The Treeline 300 Yards Behind You, Tracking Your Every Move Through A Sniper Scope
  • Local time:10:00 AM

Posted 28 October 2007 - 11:45 PM

Hi nosnhoj#3,

This seems to be a pretty well written and informative 'howto' that you have here. I am toying around with an Apache web server and this seems to be something that I need to learn more about.

Up until a couple of days ago I didn't have a .htaccess file. Then while perusing an article on securing a server with a password I decided to give it a go and see what that was all about. I followed the instructions that were given to create a password file, htpasswd, and by the time that I had gotten through I had created both a htpasswd, and a .htaccess file.

The .htaccess file looks like this -->

AuthType Basic
AuthName "WARNING!This Is A SECURE AREA, PLEASE LOG IN"

AuthUserFile "c:\Documents and Settings\ADMIN\my_password_file.txt"
AuthGroupFile /dev/null

<Limit GET POST PUT>
require valid-user
</Limit>

That sucker worked too :thumbsup: , it made me have to sign in! But that's all that's in it at the moment. Do I just add more lines to make it redirect people to different pages?

OK, now I'm trying to figure out where to put it. According to the way that I'm understanding this -->

NOTE: If you created the file, it is important that you upload the file to the Root Directory of your site, which is the directory where your default "index" or "home" page resides. <--

Then my path to that file should look something like this --> C:\Program Files\Apache Group\Apache2\htdocs\.htaccess <-- right? I mean because that's where the default index thingy is.

Thanks for any insight Boo.

♥ Wendy
TRUST NO ONE...! EXCEPT For The Beloved Computer Geek Helping You In The MALWARE FORUMS.

Do Unto Others Before They Have A Chance To Do Unto You.

HP Pavilion 512n [Rescued from a pile of trash on the side of the road] 128 MB SDRAM, 60 GB Hard Drive, Windows XP, Home Edition, SP3, COMODO Anti Vitus and Firewall.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users