English 中文(简体)
Ignore symlinks in clean URL s in .htaccess
原标题:

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 :)

最佳回答

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]
问题回答

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.





相关问题
Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

Multiple Sites with common files

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, I currently duplicate the files each time I create a new site and upload different css and images. What ...

http server validation

I finish a litle http server, writing from scratch. I would like to be sure that my imlementation is conforme to the HTTP specifications. W3C give us tools for HTML/XML conformance, but i see nothing ...

热门标签