1

I have an index.html in my /Users/igor/Sites/MySite folder (igor is my username on Mac). Links (for example: <a href="/page">Page</a>) all go to localhost/page instead of http://localhost/~igor/MySite/page. http://localhost reports It works!, in http://localhost/~igor/ I see all my files and folders.

My /private/etc/apache2/users/igor.conf file:

<Directory "/Users/igor/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>  

My /private/etc/apache2/extra/httpd-userdir.conf file (without comments):

UserDir Sites  
Include /private/etc/apache2/users/*.conf
<IfModule bonjour_module>
       RegisterUserSite customized-users
</IfModule>  

Also I uncommented lines in httpd.conf as described here.

Some lines from my httpd.conf:

User _www
Group _www


 <Directory />
    AllowOverride none
    Require all denied
</Directory>  



<Directory "/Library/WebServer/Documents">
    Options FollowSymLinks Multiviews
    MultiviewsMatch Any

    AllowOverride None

    Require all granted
</Directory>

httpd -V output:

Server version: Apache/2.4.23 (Unix)
Server built:   Aug  8 2016 16:31:34
Server's Module Magic Number: 20120211:61
Server loaded:  APR 1.5.2, APR-UTIL 1.5.4
Compiled using: APR 1.5.2, APR-UTIL 1.5.4
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_FLOCK_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/usr"
 -D SUEXEC_BIN="/usr/bin/suexec"
 -D DEFAULT_PIDLOG="/private/var/run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="/private/etc/apache2/mime.types"
 -D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf"

How to fix links so they correspond to Sites/MySite/MyLink and not localhost/MyLink? Thanks.

Update: httpd -t -D DUMP_RUN_CFG returns:

[Thu Oct 13 16:55:24.277291 2016] [so:warn] [pid 46810] AH01574: module php5_module is already loaded, skipping
AH00112: Warning: DocumentRoot [/usr/docs/dummy-host.example.com] does not exist
AH00112: Warning: DocumentRoot [/usr/docs/dummy-host2.example.com] does not exist
ServerRoot: "/usr"
Main DocumentRoot: "/Library/WebServer/Documents"
Main ErrorLog: "/private/var/log/apache2/error_log"
Mutex default: dir="/private/var/run/" mechanism=default 
Mutex mpm-accept: using_defaults
PidFile: "/private/var/run/httpd.pid"
Define: DUMP_RUN_CFG
User: name="_www" id=70 not_used
Group: name="_www" id=70 not_used  
  • Just a hint..."line numbers" are irrelevant in httpd.conf you need to reference the directives (like DocumentRoot). Directives can be located anywhere in httpd.conf and httpd.conf files differ by distro, Apache version and by user so line numbers don't help. – Allan Oct 13 '16 at 12:38
  • I'm not seeing DocumentRoot, but I see that you have a directory in /Library/WebServer/Documents/. Execute this command: httpd -t -D DUMP_RUN_CFG and post the results. – Allan Oct 13 '16 at 13:27
  • @Allan Added results in question. – Igor Rusinov Oct 13 '16 at 13:59
  • Somewhere in your httpd.conf your DocumentRoot is not set properly because httpd doesn't have the correct value. See the value "Main Document Root". You will need to go through your httpd.conf files (including the custom ones) and make sure you are setting the directive properly; there should be only one and should only be in the main `httpd.conf' – Allan Oct 13 '16 at 14:09
  • @Allan DocumentRoot and <Directory ... > should be Users/igor/Sites/? – Igor Rusinov Oct 13 '16 at 14:27
1

You have to set the DocumentRoot directive in your httpd.conf. First, using your favorite editor, search for the DocumentRoot directive and add the following:

 DocumentRoot "/Users/igor/Sites/MySite/MyLink"

Restart Apache so that it reads the updated directive from httpd.conf

  • Did it, link still goes to localhost/MyLink and gives me Error 403 Forbidden. – Igor Rusinov Oct 13 '16 at 12:50
0

I don't think anything is configured incorrectly - I think your HTML is wrong. Anything in your Sites folder containing a link like <a href="/page">page</a> will ALWAYS go to localhost/page.<a href="page">page</a>, on the other hand, will resolve to localhost/~igor/page as you intend.

The slash preceding the target in the first example redirects it to whatever directory is set as your DocumentRoot (e.g. the folder that corresponds to localhost).

  • Fair enough. Didn't think about it at first for some reason. – Igor Rusinov Oct 13 '16 at 19:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .