Forum Moderators: phranque

Message Too Old, No Replies

.htaccess redirection

.htaccess redirection

         

vwsequeira

9:33 am on Apr 26, 2005 (gmt 0)

10+ Year Member



Hello,

I have a domain name example.com . I have a folder /html in my hosting account. I want to point the domain to that folder. Right now it points to the root. Could you please tell me what code I need to add to my .htaccess file? Also the browser should show the original URL and not the redirected URL while accessing.

Thanks,

Vincent

[edited by: jdMorgan at 2:20 pm (utc) on April 26, 2005]
[edit reason] Examplified. [/edit]

sitz

12:50 pm on Apr 26, 2005 (gmt 0)

10+ Year Member



If you have write access to the server's httpd.conf (or can convince the person(s) who do to make a change for you), the best solution is to repoint the DocumentRoot to the html/ directory.

If this isn't an option for some reason, the other solution is a mod_rewrite-based on, with the Rewrite directives in a .htaccess file. Note that in order for this to work, the server must be configured with the mod_rewrite module loaded, and the 'FileInfo' option must be applied to the AllowOverride directive which applies to your *current* DocumentRoot. If all these apply, then something like the following in a .htaccess file:


RewriteEngine on
#
# If we don't exclude /html/ from the Rewrite'ing,
# we'll wind up in an infinite loop. Yick.
RewriteCond %{REQUEST_URI}!^/html/
#
# Rewrite
RewriteRule ^(.*) /html/$1 [L]

For more information on how mod_rewrite works, check the links in the forum charter [webmasterworld.com].

vwsequeira

9:19 am on Apr 27, 2005 (gmt 0)

10+ Year Member


Hello Sir,

That information really helped us a lot.

Ours is a shared hosting platform and my hosting account is hosted on UNIX, apache web server. On this platform every individual hosting account has got hidden .htaccess file. Using FTP we can download and add codes to this file. Can you please give me a tutorial link on the net where I can find the full configuration of this .htaccess file? I searched on net but didn’t get any easy to understand link.

Thanks,
Vincent

sitz

12:10 am on Apr 28, 2005 (gmt 0)

10+ Year Member



I'm not aware of one off-hand; I would read through the Apache directives documentation [httpd.apache.org]. Any directive that has an 'override' listed can *potentially* be used in a .htaccess file. As an example, AddAltByType [httpd.apache.org] does, but AddModule [httpd.apache.org] does not; they're listed (or not) in the first part of the documentation for each directive.

The next thing you'll need to take note of is the value of the 'Override' for a particular directive. If you want to use a particular directive in a .htaccess file, the argument to 'Override' (in the case of AddAltByType, the Override is 'Indexes') MUST be used an an argument to the AllowOverride directive which applies to the directory in which you're placing the .htaccess file.

Get that? =)

For instance, let's say you want to place a .htaccess file in:


/var/www/domains/example.com/htdocs/images/

You'd check to see which Override applies to the directive you want to place in the .htaccess file. Let's say, for the purposes of this example, that the Override is 'Indexes'; In order for that directive to work in your .htaccess file, the server's httpd.conf would need something like:

<Directory /var/www/domains>
AllowOverride Indexes
(other directives)
</Directory>

The '<Directory>' could be *any* directory leading up to your images/ directory; the rules inherit as you go deeper into filesystem directory structures.

Of course, if you place an directive in a .htaccess file that's disallowed by httpd.conf, you'll get a 500 Internal Server Error when you try and access a page in the directory with the .htaccess file. Of course, you'll also get that error if you've misconfigured a directive in your .htaccess file.

Does this help?