SymLinks not being followed in htaccess

August 3, 2013 14.9k views
I have CentOs with Apache. In my httpd.conf I have Options FollowSymLinks AllowOverride None and further down ServerAdmin me@mydomain.com DocumentRoot /var/www/mydomain.com/public_html ServerName www.mydomain.com ServerAlias mydomain.com ErrorLog /var/www/mydomain.com-error_log CustomLog /var/www/mydomain.com-access_log common Options +FollowSymLinks AllowOverride All Order allow,deny Allow from all And in my .htaccess in my public_html folder I have at the top: RewriteEngine On Options +FollowSymLinks However, the links (e.g. a RewriteRule $ /error/mypage.htm [R=302,L]) are generated as: /var/www/error/mypage.htm rather than: /var/www/mydomain.com/public_html/mypage.htm any ideas? thanks
33 Answers
I have CentOs with Apache.

In my httpd.conf I have

\
Options FollowSymLinks
AllowOverride None
\

and further down

\
ServerAdmin me@mydomain.com
DocumentRoot /var/www/mydomain.com/public_html
ServerName www.mydomain.com
ServerAlias mydomain.com
ErrorLog /var/www/mydomain.com-error_log
CustomLog /var/www/mydomain.com-access_log common
\
Options +FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
\
\

And in my .htaccess in my public_html folder I have at the top:

RewriteEngine On
Options +FollowSymLinks


However, the links (e.g. a RewriteRule $ /error/mypage.htm [R=302,L]) are generated as:

/var/www/error/mypage.htm

rather than:

/var/www/mydomain.com/public_html/mypage.htm


any ideas?

thanks
P.S. repost as I didnt know i had to escape
oki given up on trying to escape this, grr
I have CentOs with Apache.

In my httpd.conf I have

Directory /
Options FollowSymLinks
AllowOverride None
/Directory

and further down

VirtualHost *:80
ServerAdmin me@mydomain.com
DocumentRoot /var/www/mydomain.com/public_html
ServerName www.mydomain.com
ServerAlias mydomain.com
ErrorLog /var/www/mydomain.com-error_log
CustomLog /var/www/mydomain.com-access_log common
Directory /
Options +FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
/Directory
/VirtualHost


above are bits that wouldnt escape with the less than/more than signs removed
Please pastebin the Virtualhosts - http://pastie.org
what all of them? I dont really want all the info online forever
Here's the full file with just some privacy changes:

i.e. mydomain.com being one domain, mydomain2.com being another completely different domain name etc

http://pastie.org/private/e5kvbwzk39wn33l71ug
If you want to enable symlinks for the first virtualhost (/var/www/mydomain.com/public_html), add this before </VirtualHost>

https://p.kk7.me/tuhotijunu.xml (make sure you restart Apache after editing the file).

Let me know if that fixes it.
I've tried that.

Maybe this issue is unrelated to symlinks in fact, sorry for the confusion I'm not sure whats really going on.

Here's the issue:

I've tried using a RewriteBase but that won't work either.

On my old host this used to work fine.

should come out as:

http://mydomain.com/mypage.htm

and find the page

but now it comes out as:

http://mydomain.com/full_server_path_to_file

and doesnt load the page
Paste the contents of .htaccess
The mapping between path and url seems not to be working right basically
http://pastie.org/private/ui73e7gkigywrrn12je5q
The XXX are just to hide the IP
Even when the file path it's looking for is correct it says it cant be found on the server.
The requested URL /var/www/mydomain.com/public_html/mypage.htm was not found on this server.
In looking at http://pastie.org/private/e5kvbwzk39wn33l71ug#, doesn't each virtual host need the AllowOverride All parameter?
Hi, well the one I'm using has one. Isn't that enough? I'm not quite sure what AllowOverride All entails, is it safe to enable all this stuff?

So with a ScriptAlias I now seem to have CGI path correct and executable, latest problem is I don't have permissions to access (I have checked chmod and "apache" is the group user).

Also all other files are still inaccessible due to incorrect path, as previously.

I feel like I'm going round in circles!
Forbidden

You don't have permission to access /cgi-bin/index.cgi on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Related to the forbidden error I'm getting "Options ExecCGI is off in this directory" in the error log.

I am trying to enable this for certain directories but perhaps incorrectly:

http://pastie.org/private/tz7qhkmqhgifp7lki98jxg
Take a look at your line 402, which reads:
DirectoryIndex index.html index.html.var


I wonder if you don't need to add more file types?
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
I have got around this by enabling ExecCGI for the whole websites folder, which isnt exactly what i wanted to do.

Anyway, now I'm back to the initial problem of none of the files being found in the mod_rewrite.

Not Found

The requested URL /var/www/mydomain.com/public_html/mypage.htm was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
So DirectoryIndex is where it looks for an initial file? I don't think that applies as I have mod_rewrite doing everything in the background, i.e. it redirects from base url, or any index file (index.html, index.php etc.) to index.cgi
I think you need to add two lines to each of your Virtual Hosts (lines 1009 - 1078). Under each DocumentRoot /var/www/..., insert:
 

  AllowOverride Fileinfo Options
Oops, that was supposed to read:
<Directory /var/www/...>


and if AllowOverride Fileinfo Options doesn't work, THEN try AllowOverride All
I've added "allowoverride all" to all my virtual hosts (most of which are empty i should point out), it has brought me back an old error I previously had but resolved. I get apache test page and error:

Directory index forbidden by Options directive: /var/www/mydomain.com/public_html/
Hi, Thanks managed to get it sorted now with your help and other bits of fiddling around. The allowoverride all fixed it but there were some other issues I had to resolve first to get it working properly :)
So I realised what was causing the problem of the URLs not being found. I had "RewriteEngine On" at the top of my .htaccess and removing this fixed it (I noticed this after I accidentally uploaded an old version and ran into the same problem again).
OK I tell a lie, I'm getting myself confused. I did have this working last night but its no longer working when i got up this morning. The RewriteEngine being off just redirected to index.html hence my confusion.
So either it was working last night and it has mysteriously broken today, or 24 hours without sleep took it's toll on my last night and I thought it was fixed!

my httpd.conf
http://pastie.org/private/xeunirxaevku22ycvmvjw

my .htaccess (extract of, all links behave the same way)
http://pastie.org/private/b0p6308m4g31s7c3qvkbg

Basically it tries to fetch:

http://mydomain.com/var/www/mydomain.com/public_html/error/updating.htm

with an absolute url e.g. /error/updating.htm I get:

http://deepundergroundpoetry.com/error/updating.htm

This appears correct but the file is "not found" (and of course it can't find the 404.html either because it cant find anything!)
Try commenting out all the rules in .htaccess - does it work without it?
So the rest of the site functions fine it just seems to be the ErrorDocument in particular that is perhaps getting blocked by .htaccess. I managed to get it to work by moving them from /var/www/mydomain.com/public_html/error to /var/www/error/mydomain and changing the httpd.conf paths e.g.

ErrorDocument 404 /mydomain.com/public_html/error/404.htm

This works, but it won't load the images on the page. I have them in the same folder and reference them like img src="404.jpg" in the code
One way to fix this is to just base64 the image and use it as a data uri in the img element: http://css-tricks.com/data-uris/
Perfect, thanks so much, I never thought to do that :)
Have another answer? Share your knowledge.