SitePoint Sponsor

User Tag List

Results 1 to 15 of 15

Thread: Applying a RewriteRule to a an Alias folder (overriding Aliases with RewriteRules)

  1. #1
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    New Jersey
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Applying a RewriteRule to a an Alias folder (overriding Aliases with RewriteRules)

    I have an account (say "user1") where httpd.conf contains an Alias to another account's folder:
    Code:
    Alias /redir /home/user2/public_html/
    I'd like to apply RewriteRules in .htaccess for the /redir folder, but .htaccess sems to just ignore the rules I try. For instance rewriting redir/test to the test.php for user1:
    Code:
    RewriteRule redir/test.php test.php
    This rule seems to simply be ignored - the URL redir/test goes to user2/public_html/test.php, if it exists, following the Alias. I also tried it with the full path
    Code:
    RewriteRule redir/test.php /home/user1/public_html/test.php
    What is the correct way to write RewriteRules that can override the Alias directive?

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,318
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    Kad,

    You can't. mod_alias (redirect) takes precedence over mod_rewrite so mod_rewrite can NEVER override a mod_alias directive.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    New Jersey
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. Then is there any way using .htaccess only to rewrite URLs for one account to file locations under another account? For instance placing something like this in the .htaccess of user1, which failed when I tried it:
    Code:
    RewriteRule redir/test.php /home/user2/public_html/test.php
    Or by some other means.

    And/or, perhaps there is some way to use regex in httpd.conf to create an Alias for everything except a certain file or folder(s)?

  4. #4
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    New Jersey
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is regex allowed inside an Alias directive?

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,318
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    Kad,

    "account?" If you mean owned by different people, I certainly hope not (except with an absolute redirect)!

    I don't use Alias - even for cgi-bin - as it puts the files in other places (often out of the webspace).

    WHAT are you REALLY trying to do?

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    New Jersey
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a dedicated server, with two different cpanel accounts. I need to have a subfolder of one account deliver content from a script located on another account, and I need to apply some on top of that RewriteRules also.

    For instance I want /user1/public_html/redir to deliver content from /user2/public_html/somescript.php.

    A simple php include doesn't quite work, because of path issues - the script is a CMS that uses a bunch of folders (e.g. /user2/public_html/images/...), and the browser doesn't translate the path from domain.com/redir/images to domain.com/images.

    An Alias solves that issue, and domain.com/redir/images will be interpreted by the server as /images, however I also need to apply some RewriteRules, which as you say won't work because the Alias overrides them. So it's a case of the php include allowing RewriteRules but breaking due to path translation issues, or an Alias that doesn't have path translation issues but doesn't allow RewriteRules.

    What do you mean by "absolute redirect"? I googled this but couldn't figure it out.

  7. #7
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,318
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    Kadence,

    An absolute redirect is either external (http://domain/path/to/file) or internal (/path/to/file). This is differentiated from relative links as they are subject to the (perceived) location of the file being accessed. Since mod_rewrite can often change the directory level, absolute URLs are necessary (if you don't use the <base> tag).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  8. #8
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    New Jersey
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, but I don't really follow

    The links I am trying to rewrite are absolute links - e.g. if the user1 account's domain is domain1.com, then in the HTML what I'm trying to rewrite is linked as http://www.domain1.com/redir/test.php. And the rewrite rule would be something like as above,
    Code:
    RewriteRule redir/test.php /home/user2/public_html/test.php
    I thought perhaps you mean an absolute link in the RewriteRule, so I alternatingly attempted each of the following as well:
    Code:
    RewriteRule http://www.domain1.com/redir/test.php /home/user2/public_html/test.php
    RewriteRule http://www.domain1.com/redir/test.php http://www.domain1.com/home/user2/public_html/test.php
    RewriteRule redir/test.php http://www.domain1.com/home/user2/public_html/test.php
    Though none of those made a difference.

    What specifically would I have to modify to get this to work?

  9. #9
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,318
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    Kad,

    mod_rewrite deals with HTTP requests so the internal absolute path is relative to DocumentRoot, NOT the server's physical path (error #1). NEVER use the http: protocol in a RewriteRule's regex (because a RewriteRule attempts to match the {REQUEST_URI} string, not the entire URL; error #2).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  10. #10
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    New Jersey
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    Kad,

    mod_rewrite deals with HTTP requests so the internal absolute path is relative to DocumentRoot, NOT the server's physical path (error #1). NEVER use the http: protocol in a RewriteRule's regex (because a RewriteRule attempts to match the {REQUEST_URI} string, not the entire URL; error #2).

    Regards,

    DK
    Yes I knew that was likely not going to do anything productive and was experimenting just in case, but I am just unclear on what you are getting at in terms of what the solution here is...?

  11. #11
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,318
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    Kad,

    As above, my solution is that there is no solution (unless you go "over the top" and use a domain which encompasses the subdomains/subaccounts). You just can't get there from here!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  12. #12
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    New Jersey
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see - unfortunately that means a lot of extra work for me then

    What about Aliases and regex - can one use regex with Aliases?

  13. #13
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,318
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    Kad,



    Some of them - see the link I'd provided (RedirectMatch).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  14. #14
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    New Jersey
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you. I just read about the AliasMatch directive, which I think is exactly what I need.

    Having another issue with that though where it displays the directory listing instead of the actual content, but I think I should make a separate thread for that. Thanks again

  15. #15
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,318
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)


    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •