1

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.

2 Answers 2

1

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.

7
  • I put DirectoryIndex index.php in public_html, but it still serves index.html Commented Nov 14, 2011 at 19:19
  • Then replace with this rule: RewriteRule ^$ /index.php [L] Commented Nov 14, 2011 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. Commented Nov 14, 2011 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 /? Commented Nov 14, 2011 at 19:27
  • You need RewriteEngine On Commented Nov 14, 2011 at 19:31
0

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.