Forum Moderators: phranque

Message Too Old, No Replies

new to htaccess

just a few questions

         

too much information

2:39 am on Feb 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



should I have an htaccess file in every folder, or just in folders that are supposed to be password protected?

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?

too much information

12:47 pm on Feb 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I figured out the 301 redirect question. I also read that I can just create the htaccess file in the root directory of my site, but I still get a configuration error when I put the file online. So:

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.?

jdMorgan

3:07 pm on Feb 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> should I have an htaccess file in every folder, or just in folders that are supposed to be password protected?

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

too much information

3:39 pm on Feb 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yea, I'm always weary of cut and paste code. But I think I misunderstood one of the examples that I found online.

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...]

jdMorgan

3:52 pm on Feb 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A redirect requires a canonical URL, so you'd have to use the first "long" version. This, being a redirect, involves sending a redirect response to the client including the new URL, which terminates the current HTTP transaction. The client then changes the URL shown in its address bar, and re-issues the request using the new URL.

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

Mr Bo Jangles

4:57 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



Great advice Jim - very helpful posts, thank you.

Cheers,

too much information

5:35 pm on Feb 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for all of the help, after a few errors earlier, it works perfectly now.

I'll iron out all of the mod_rewrite stuff later, right now I am concerned with loosing my SERPs after switching from ASP to PHP. It's just one more bullet to dodge. ;o)

PS - Dreamweaver is htaccess friendly