Forum Moderators: phranque
can I use my htaccess file to return a 301 redirect for a specific page to a specific page?
I'm on a RedHat linux server, apache 2.x where would I find my primary htaccess file, or can I just create one in my website's root folder?
more questions...
what read/write permissions do I need to set for my htaccess file?
is there a specific set of code that is required at the beginning of an htaccess file or can I just start off with my redirects?
can I create this file using dreamweaver (code view of course) or do I need to edit this thing with Notepad/Pico, etc.?
There is no need to have one in each folder -- You put them where you need them to accomplish what you need to do. Password protection is only one of the many functions you can implement in .htaccess. .htaccess files are processed hierarchically, with lower-level-directory .htaccess files capable of overriding more general settings at higher levels. One big .htaccess file in Web root can be used to centralize management of the functions, or many lower-level .htaccess files can be used to improve run-time efficiency; .htaccess files are interpreted for each HTTP request, so a very large .htaccess located at Web root might be convenient to manage, but rather inefficient.
> can I use my htaccess file to return a 301 redirect for a specific page to a specific page?
Yes, you can use either mod_alias or mod_rewrite in .htaccess to do redirects.
> I'm on a RedHat linux server, apache 2.x where would I find my primary htaccess file, or can I just create one in my website's root folder?
You usually need to create one. See answer #1 for more details.
> what read/write permissions do I need to set for my htaccess file?
Owner read plus system read should work. .htaccess is processed server-side, and Web access is not usually desirable.
> is there a specific set of code that is required at the beginning of an htaccess file or can I just start off with my redirects?
This depends on the module you are using to do the redirect. mod_alias requires no setup, but has limited capability, while mod_rewrite, which has more capabilities, needs some setup.
> can I create this file using dreamweaver (code view of course) or do I need to edit this thing with Notepad/Pico, etc.?
I'm not familiar with DW, but I'd recommend a plain-text editor to create a test file. Get it working and then try your other editors. If the previously-working file still works after editing it to add a comment or make a minor change using DW code view, then you're fine. For efficiency, a Unix text-format file with LF-only line-enders is preferred.
Think of .htaccess only as a directory-level configuration container file. All the details are in the actual modules that process your .htaccess.
<advice> Start simple and build on working code in small steps. We get a lot of posts here from new users asking why their .htaccess file doesn't work, and the posted code is 35 lines long and none of it works. After some discussion it then becomes clear that the poster copied all of it, understands none of it, and does not understand the terminology required to describe a fix. In cases like this, it is very hard to help them if they won't review and try to understand the documentation and the code.
So if you use code you find posted here or elsewhere on the Web, look up the Apache modules and directives that are used in that code and understand it before you try to use it. This will save you from a lot of problems and frustration. Remember that .htaccess is a server configuration file; One subtle error in .htaccess can undo all the effort you've put into thousands of lines of php code or database entries, stop your server, and ruin your search engine rankings. The code needs to be absolutely correct. Study is warranted.</advice>
Jim
For a redirect you can use:
Redirect /service [foo2.bar.com...]
But can I use:
Redirect /service.asp /service.php
or do I need to use:
Redirect /service.asp [mydomain.com...]
If you wish to simply re-map the file on the server associated with a given URL, then you'll need to use mod_rewrite to do a rewrite rather than a redirect.
Jim