Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess config with symbolic links and index files not working as expected

Like a lot of web developers, I like to use .htaccess to direct all traffic to a domain through a single point of entry when the request isn't for a file that exists in the publicly served directory.

So something like this:

RewriteEngine On
# enable symbolic links
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+) index.php [L]

This means if the request isn't for a css file or an image, my index.php gets the request and I can choose what to do (serve up some content or perhaps a 404)

Works great, but I've stumbled upon an issue it can't seem to help me solve.

My document root looks like this:

asymboliclink -> /somewhere/else
css
.htaccess
img
includes
index.php

Yet, Apache doesn't see the symbolic link to a directory as a directory. It passes the request on to my index.php in the root. I want to serve the link as if it were a folder as it is a link to a folder with it's own index.php. I can access http://example.com/asymboliclink/index.php by typing it in the address bar of a browser, but I want to be able to access it through http://example.com/asymboliclink

What do I need to add to my .htaccess file to make this happen?

like image 557
poolnoodl Avatar asked Mar 23 '11 23:03

poolnoodl


People also ask

Why is my .htaccess file not working?

Improper syntax being used It is quite common for a syntax error to be the reason for an . htaccess file not working. If you are familiar with how to read and configure . htaccess rules, double check your configuration.

What is htaccess file example?

htaccess file can be found primarily in your website's root folder, for example: /var/www/html/. Essentially, every directory on the webserver can have a '. htaccess' file. Each directory can have only one .


2 Answers

Use the -l switch to test for a symbolic link

RewriteEngine On
# enable symbolic links
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+) index.php [L]

Documentation

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html - ctrl+f for "Treats the TestString as a pathname and tests whether or not it exists, and is a symbolic link."

like image 97
Jason Avatar answered Sep 22 '22 19:09

Jason


The -l flag references symbolic links

RewriteEngine On
# enable symbolic links
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+) index.php [L]
like image 34
Michael McTiernan Avatar answered Sep 19 '22 19:09

Michael McTiernan