Forum Moderators: phranque

Message Too Old, No Replies

use .htaccess to change the home page

use .htaccess to change the home page

         

phparion

9:59 am on Oct 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




hi

i have a site under my domain's root folder and index.php page is picket automatically when domain is called i.e

www.mydomain.com/index.php

but i want to send the request to another folder and index.php page in that folder should be browsed when domain name is called.. i.e

when www.mydomain.com is called it should take the visitor to www.mydomain.com/newfolder/index.php

but when someone writes www.mydomain.com/index.php then it must show the original index.php under root folder.

how can i do it with .htaccess?

thanks
________

jdMorgan

5:03 pm on Oct 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A mod_rewrite rewriterule with a rewritecond to make an exception for the index page can do this easily.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

DTriplett

5:46 am on Oct 9, 2006 (gmt 0)

10+ Year Member



Another option, using .htaccess (like you requested) is:
DirectoryIndex /newfolder/index.php
(From [httpd.apache.org...]

phparion

6:00 am on Oct 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



i used the following in .htaccess in my root folder and it started to redirect requests to the new folder.

DirectoryIndex /newfolder/index.html

But now i have started to face a problem with this .htaccess code,

I am redirected to /newfolder/index.html whenever a querystring is called by some application anywhere, e.g

on my blog i have links to comments as

[domain.com...]

but instead of showing this post i am redirected to the
[bizfriendz.com...]

same is happening for the urls like
[bizfriendz.com...]

it doesnt pick the index.php in the chat folder but brings me to the /newfolder/index.html

how can I control it? I dont want to be redirected like this but I just want to redirect users who types my main domain i.e

www.mydomain.com when browsed should go to www.mydomain.com/newfolder/index.html

I also tried the following code in .htaccess ,

<LocationMatch "^/$">
DirectoryIndex /newfolder/index.php
</LocationMatch>

the idea behind this was to redirect root folder requests only to the new folder otherwise dont redirect.

but now i am getting 500 internat server error.

thanks in advance

jdMorgan

1:52 pm on Oct 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can't use LocationMatch in .htaccess -- Check the "context" specification for each Apache directive. For "LocationMatch", .htaccess is not in the list of allowed contexts. Therefore, you get a 500-Server Error.

You can (and should) check your server error log to confirm this.

As your requirements expand, the number of available solutions decreases. It's a good idea to spend your time tightly defining the problem before looking for a coded solution.

If you wish to redirect only root directory index requests with blank query, then I'd suggest:


Options +FollowSymLinks -MultiViews
RewriteEngine on
#
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^$ /newfolder/index.php [L]

Note that any links or included HTTP objects (images, CSS files, scripts) on the /newfolder/index.php page may need to be referenced using server-relative or canonical URLs. Otherwise, the client will resolve page-relative links based upon the original URL it asked for, not the rewritten URL. This may or may not be a problem; You'll be able to tell instantly when loding the rewritten page the first time -- If images, CSS, and external JS are borken, then you'll need to correct the links or provide more rules to correct those requests.

Jim