Solved

.htaccess doesn't work from subdirectory

Posted on 2011-09-13
7
398 Views
Last Modified: 2012-06-22
I'd like to let people put www.mysite.com/trial into a browser and get directed to www.mysite.com/trial.php. That is, I don't want to force them to put in www.mysite.com/trial.php.  

So I put a trial directory under the root directory with an index.html file and a .htaccess file that contains:

Redirect   /index.html http://www.mysite.com/trial.php

But this doesn’t redirect. You go right into trial/index.html page.

I can do .htaccess redirects ok if I put the .htaccess file in the root directory of the site, so I'm thinking that .htaccess doesn't work in a subdirectory.

Is this the case?

Thanks for any info.
Steve
0
Comment
Question by:steva
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 21

Accepted Solution

by:
Papertrip earned 250 total points
ID: 36533373
Put this in your .htaccess file in /trial
DirectoryIndex trial.php

Open in new window


Or just change trial.php to index.php, which is probably already in the global DirectoryIndex
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 36533375
Or just change trial.php to index.php, which is probably already in the global DirectoryIndex

To be clear I meant rename the file trial.php to index.php
0
 
LVL 12

Assisted Solution

by:larsrohr
larsrohr earned 250 total points
ID: 36533676
Your .htaccess isn't quite right.
You aren't trying to match "/index.html" -- you should be trying to match "/trial/index.html":

Redirect   /trial/index.html http://www.mysite.com/trial.php

0
Building an interactive eFuture classroom

Watch and learn how ATEN provided a total control system solution including seamless switching matrix switch, HDBaseT extenders, PDU, lighting control to build an interactive eFuture classroom.

 
LVL 21

Expert Comment

by:Papertrip
ID: 36533685
That is only going to work if the GET request has /index.html in it.
0
 
LVL 12

Expert Comment

by:larsrohr
ID: 36533707
It works fine on my server.
Browser asks for "/trial"; server says Well, I have a directory by that name; my server's DirectoryIndex setting uses index.html, so it interprets this request as wanting "/trial/index.html"; and then .htaccess kicks in and the Redirect sends it to "/trial.php".
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 36533726
I stand corrected.
0
 

Author Closing Comment

by:steva
ID: 36539113
Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question