Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a web site on a shared hosting server. My directory layout looks like this

/home
    /user
        /public_html
            /pics
                /family

There is an index.php file in public_html. I need help writing .htaccess rules that will

  1. Serve the index.php file when www.domain.org is requested
  2. Force the user back to public_html when www.domain.org/pics is requested
  3. Allow the user to see the directory contents when www.domain.org/pics/family is requested

I experimented with a lot of combinations of RewriteCond and RewriteRule, but I don't understand the documentation and examples well enough to know if what I want to do is even possible.

The web server application is some version of Apache.

share|improve this question

2 Answers 2

1) You can get this one for free by adding a DirectoryIndex index.php in your .htaccess file that's sitting in public_html.

2) To reroute requests to /pics, you can use this set of rewrite rules:

RewriteRule ^pics/?$ http://www.domain.org/ [R,L]

3) You'll need to use the with Options:

<Directory "/home/user/public_html/pics/family">
    Options Indexes
</Directory>

You'll need to make sure in your webserver conf or virtualhost conf that you can override options in your .htaccess files. Something like AllowOverride All or AllowOverride Indexes. Also note that with #2, people will still be able to access the files in pics, e.g. http://www.domain.org/pics/pic1.jpg, but will get redirected if attempting to just access the directory.

share|improve this answer
    
I put DirectoryIndex index.php in public_html, but it still serves index.html –  MountainRider Nov 14 '11 at 19:19
    
Then replace with this rule: RewriteRule ^$ /index.php [L] –  Jon Lin Nov 14 '11 at 19:24
    
So far, the only success I have is to put Options Indexes in pics and family. My ignorance of the correct syntax for RewriteRule and RewriteCond just causes the server to report 503 or some other error. –  MountainRider Nov 14 '11 at 19:25
    
ok. I have a .htaccess in public_html with only RewriteRule ^$ /index.php [L] and it still serves index.html. Are there any other lines I need to add, like RewriteEngine On or RewriteBase /? –  MountainRider Nov 14 '11 at 19:27
    
You need RewriteEngine On –  Jon Lin Nov 14 '11 at 19:31
up vote 0 down vote accepted

I put this in public_html/.htaccess

RewriteEngine On
RewriteCond %{REQUEST_URI} "/pics/" [OR]
RewriteCond %{REQUEST_URI} "/pics/family/"
RewriteRule (.*) $1 [L]

There is nothing in public_html/pics/.htaccess
I put this in public_html/pics/family/.htaccess

Options +Indexes

I removed index.html.

After that, everything worked the way I wanted it to work. I got the idea from this Drupal documentation.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.