WikyBlog
Download

Home > Talk > htaccess question

What do I need to put in the .htaccess file so that users can see into other directories on my server? I know it has to do with:

		# RewriteCond %{REQUEST_FILENAME} !-d [nc]
		RewriteCond %{REQUEST_FILENAME} !-f [nc]

But I don't know much more than that.

Solution

Ok, I think we can do that. So we want to keep the wiki.php file from being accessed when the user requests a directory. You'll want to uncomment the first RewriteCond, and there's another line in the .htaccess file that prevents directories from being indexed: Options -Indexes. So you'll have this...

		#Options -Indexes
		RewriteCond %{REQUEST_FILENAME} !-d [nc]
		RewriteCond %{REQUEST_FILENAME} !-f [nc]

The !-d tests %{REQUEST_FILENAME} to see if it's an existing directory. The !-t does the same thing but for existing files. --Main 06:14, May 15, 2006

Followup

I tried different combinations of that with no success... I got 403 and 404, or saw the contents of my root directory - depending on which lines I commented and uncommented...

Lets say the directory I want to access is /stats what exactly would i change in the htaccess... it currently looks like this >

	
	Options -Indexes
	
	#	Set some php values if we can
	php_value magic_quotes_gpc 0
	php_value magic_quotes_runtime 0
	php_value magic_quotes_sybase 0
	
	php_flag register_globals off
	
	
	
	#	Use the RewriteEngine to make the links look beter
	# 		www.site.com/Main/Home instead of www.site.com/index.php/Main/Home
	#
	# 	If you're seeing urls with index.php, 
	#		it means your server is either not configured to allow .htaccess
	#		or the RewriteEngine is not enabled
	#
	
	#check for mod_rewrite.c
	#[nc] makes tests case insensitive
	 <IfModule mod_rewrite.c> 
		RewriteEngine On
		
		#RewriteBase
		#The default setting is; RewriteBase physical-directory-path
		
		#Skip these filetypes
			RewriteCond %{REQUEST_URI}	!\.(gif|jpe?g|png|ico|css|txt|xml|pdf|shtml|js)$ [nc]
			
		#Skip any existing file
		#Because of a potential installation into subdirectories, we no longer check for /include, /userfiles, /templates
		#not going to check for directory because root directory requests will then be sent to /index.php
			# RewriteCond %{REQUEST_FILENAME} !-d [nc]
			RewriteCond %{REQUEST_FILENAME} !-f [nc]
			

			
		#Send all other requests to wiki.php	
			RewriteRule .* wiki.php [L]
			
			# try these
			#RewriteRule ^(.*) wiki.php [L]
			
	</IfModule>

Hmm, that's right..

  • The 403 is caused by the Options -Indexes line so we definitely want to comment/delete this line.
  • Then, seeing the contents of your root directory was caused because Apache found the existing directory and decided not to Rewrite the request to the wiki.php file... I forgot about that case when I had you uncomment RewriteCond %{REQUEST_FILENAME} !-d [nc]

So what we want is for the Rewrite to not execute when Apache finds an existing directory except when it's the root directory... so I've gotten the following to work (I've taken out the comments to make it a little cleaner, this should be all you really need in your .htaccess file)

	php_value magic_quotes_gpc 0
	php_value magic_quotes_runtime 0
	php_value magic_quotes_sybase 0
	
	php_flag register_globals off
	
	 <IfModule mod_rewrite.c> 
		RewriteEngine On
		RewriteCond %{REQUEST_URI}	!\.(gif|jpe?g|png|ico|css|txt|xml|pdf|shtml|js)$ [NC]
			
		RewriteCond %{REQUEST_FILENAME} !-d [NC,OR]
		RewriteCond %{REQUEST_URI}	^/$
		
		RewriteCond %{REQUEST_FILENAME} !-f [NC]

		RewriteRule .* wiki.php [L]
	</IfModule>
Last modified 12:16 Thu, 18 May 2006 by Main. Accessed 860 times What Links Here share Share Except where expressly noted, this work is licensed under a Creative Commons License.