#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    22
    Rep Power
    0

    Rewrite rule using wrong web root directory


    I have CentOs with Apache.

    In my httpd.conf I have
    Code:
    <Directory />
    Options FollowSymLinks 
    AllowOverride None 
    </Directory>
    and further down
    Code:
    <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>
    And in my .htaccess in my public_html folder I have at the top:
    Code:
    RewriteEngine On 
    Options +FollowSymLinks
    However, the links (e.g. a RewriteRule $ /error/mypage.htm [R=302,L]) are generated as:
    Code:
    /var/www/error/mypage.htm
    rather than:
    Code:
    /var/www/mydomain.com/public_html/error/mypage.htm
    any ideas?

    thanks
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,301
    Rep Power
    7170
    Which file or directory do you have symlinked?
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    22
    Rep Power
    0
    Not sure exactly what you mean.

    My .htaccess file is in:

    var/www/mydomain.com/public_html


    Here's my full apache config with privacy modifications only

    /private/e5kvbwzk39wn33l71ug

    on pastie org
  6. #4
  7. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,301
    Rep Power
    7170
    Are you familiar with what a symlink is? I'm not quite sure if that's related to the issue you're having.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    22
    Rep Power
    0
    Well the issue is that rather than resolving the htaccess paths from the directory the htaccess file is in it is resolving them from the document root. Any ideas how I fix that?
  10. #6
  11. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,301
    Rep Power
    7170
    Try removing the leading slash on your rewrite rule:
    Code:
    RewriteRule $ error/mypage.htm [R=302,L]
    Or specifying that it should use the document root:
    Code:
    RewriteRule $ %{DOCUMENT_ROOT}/error/mypage.htm [R=302,L]
    (I renamed your thread title because this is unrelated to symlinks)
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    22
    Rep Power
    0
    Thanks for getting back to me, the problem with removing leading slash is that I then get the full path appended as a url:

    /var/www/mydomain.com/public_html/

    i.e. it's looking for:

    url:mydomain.com/var/www/mydomain.com/public_html/mypage.htm
  14. #8
  15. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,301
    Rep Power
    7170
    Oh right, I didn't see you're doing a client side redirect rather than a server side rewrite, so ignore what I wrote above.

    What is the URL in your browser after it follows the redirect? Is the issue that it's showing the contents of the wrong file?
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    22
    Rep Power
    0
    The url in browser is shown above after url: (as a new forum user I cant post a url)


    Basically every time I forget my devshed password I have to make a new account cos their forgot password functionality has been broken for years.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    22
    Rep Power
    0
    I've tried using a RewriteBase but that won't work either.

    On my old host this used to work fine as it was in original post.

    should come out as:

    url:mydomain.com/mypage.htm

    and find the page

    but now it comes out as:

    url:mydomain.com/full_server_path_to_file

    and doesnt
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    22
    Rep Power
    0
    ---
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    22
    Rep Power
    0
    So either it was working last night and it has mysteriously broken today, or 24 hours without sleep took it's toll on me last night and I thought it was fixed!

    my httpd.conf
    pastie.org/private/xeunirxaevku22ycvmvjw

    my .htaccess (extract of, all links behave the same way)
    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://mydomain.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!)

IMN logo majestic logo threadwatch logo seochat tools logo