Solved

.htaccess doesn't work from subdirectory

Posted on 2011-09-13
7
378 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
  • 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …

809 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