views:

316

answers:

2

Example URL:

example.com/user

/user is both a symlinked directory and a valid URL to content on my site. I user Horde Routes to request the content and all requests to the site go through index.php.

I currently have a .htaccess file that looks like:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

#allow cool urls
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]
#allow to have Url without index.php

But going to /user lists the directory contents rather than the webpage. Is it possible to ignore symlinks?

Additional to that is if you request:

example.com/user/some-css-file.css

That is a valid request that should not be ignored. So is it possible to allow files via symlinks to be requested, but the base symlinks themselves to be ignored and go to index.php?

Thanks :)

+1  A: 

Forget ignoring symlinks just create another RewriteRule. Place it before the "allow cool urls" rule:

RewriteCond %{REQUEST_URI} ^/user/$ 
RewriteRule (.*) /index.php [L]

So http://www.example.com/user/ or http://www.example.com/user should go to the content. The [L] should prevent further rules from being processed.

pygorex1
thanks - I probably should have said that there are quite a few symlinks (well ~10) so would rather have a catchall for this situation as more symlinks will be created in the future too.
ed209
+1  A: 

The test for !-d will fail when /user/ is requested since it’s actually an existing directory. You might want to use it without that condition and only allow direct access to existing files but not directories:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) index.php [L]

Additionally you could replace the pattern ^(.*) with !^index\.php$ so that a request for the index.php doesn’t require a filesystem lookup:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^index\.php$ index.php [L]
Gumbo