SitePoint Sponsor

User Tag List

Results 1 to 25 of 25
  1. #1
    SitePoint Enthusiast ironikart's Avatar
    Join Date
    Apr 2005
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Apache alias in .htaccess (mod rewrite question)

    Hi All,

    I need to replicate an alias directive within a .htaccess file (on a shared host, don't have access to my hosts apache conf).

    The directive is as follows:

    Code:
    Alias "/" "/var/www/core/web/index.php/"
    I've tried various configurations of mod rewrite, but it's not doing what I want. I'm a fish out of water with some of the more specific apache stuff... hoping we've got someone here who can help.

    This has got me part of the way there:

    Code:
    Options +FollowSymLinks
    RewriteEngine On
    
    DirectoryIndex index.php
    
    #Set the base uri
    RewriteBase /mysource_matrix
    #Now do some rules for redirection
    #if index, don't redirect (again)
    RewriteRule index.php   -
    #don't redirect double-underscore dirs (symbolic links)
    RewriteRule __lib       -
    RewriteRule __data      -
    RewriteRule __fudge     -
    #redirect everything else to index.php
    RewriteRule (.*)       index.php/$1 [L]
    I get apache 500 internal server error when trying to use this - the problem is the last line - it's supposed to write to a index.php symbolic link in the web root... but, it doesn't. I've tried re-writing it directly to the file and that produces the same problem.

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

    Quote Originally Posted by apache.org
    Alias directive

    Syntax: Alias URL-path file-path|directory-path
    Context: server config, virtual host
    Status: Base
    Module: mod_alias
    The Context line tells you that you can NOT use this directive in .htaccess (inA1.3) - that's the problem.

    Regards,

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

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    iron,

    Okay, I read further and wonder why you were asking about Alias!

    Anyway, **IF** you've confirmed that mod_rewrite is enabled (and tested it), then
    Code:
    #don't redirect double-underscore dirs (symbolic links)
    RewriteCond %{REQUEST_URI} !__
    #redirect everything else to index.php
    RewriteRule (.*) index.php/$1 [L]
    I think the problem was that you were not terminating the early statements with the Last flag so mod_rewrite kept truckin' through the code until it hit the EVERYTHING atom and dumped it all (including index.php) in the "subdirectory" for index.php. (IMHO, CRAZY code and you're lucky you didn't take down your server! PLEASE learn the RARE occasions when (.*) is actually the correct code to use.)

    Regards,

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

  4. #4
    SitePoint Enthusiast ironikart's Avatar
    Join Date
    Apr 2005
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the advice I inherited this from elsewhere - lucky it hasn't caused problems.

    This is how my .htaccess file looks at the moment. It's still throwing 500 internal server errors:

    Code:
    Options +FollowSymLinks
    RewriteEngine On
    
    DirectoryIndex index.php
    
    #Set the base uri
    RewriteBase /mysource_matrix
    #don't redirect double-underscore dirs (symbolic links)
    RewriteCond %{REQUEST_URI} !__
    #redirect everything else to index.php
    RewriteRule (.*) index.php/$1 [L]
    Mod rewrite is on, I'm using it for other sites on the same server, double underscores are working fine, still having issues with that last bit.

    Bear in mind, my alias' work fine on a test box - it pushes everything through to the scripts landing page... the rewrite doesn't. Are they supposed to behave in the same manner?

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    iron,

    Code:
    DirectoryIndex index.php
    
    Options +FollowSymLinks
    RewriteEngine On
    
    #Set the base uri
    RewriteBase /mysource_matrix
    #don't redirect double-underscore dirs (symbolic links)
    RewriteCond %{REQUEST_URI} !__
    # prevent loop
    RewriteCond %{REQUEST_URI} !index\.php
    #redirect everything else to index.php
    RewriteRule (.*) index.php/$1 [L]
    Regards,

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

  6. #6
    SitePoint Enthusiast ironikart's Avatar
    Join Date
    Apr 2005
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks David,

    It's got me past those internal server errors ... I'm still kinda stuck at the beginning again - it's not behaving the same as an alias directive. Not to worry though, at least it's given me a place to start.

    Thanks for your help

  7. #7
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    iron,

    What's it doing now? Add an R=301 flag so you see the redirect (GREAT for testing).

    Regards,

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

  8. #8
    SitePoint Guru LinhGB's Avatar
    Join Date
    Apr 2004
    Location
    Melbourne, Australia
    Posts
    902
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "I disapprove of what I say,
    but I will defend to the death my right to say it."

  9. #9
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    512
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I usually put the slash at the end of Rewritebase.
    RewriteBase /mysource_matrix/

    Also, your code can be further optimized like this, if you prefer.
    (Providing the code does what you want.)
    Code:
    DirectoryIndex index.php
    
    Options +FollowSymLinks
    RewriteEngine On
    
    #Set the base uri
    RewriteBase /mysource_matrix/
    #don't redirect double-underscore dirs (symbolic links)
    # prevent loop
    #redirect everything else to index.php
    RewriteRule !^/*(__|index\.php) index.php%{REQUEST_URI} [L]
    Freebie/DonationWare: check-these.info
    Custom solutions: Hostwick.com

  10. #10
    SitePoint Enthusiast ironikart's Avatar
    Join Date
    Apr 2005
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Added the extra slash, but still the same problem.

    I get:

    Code:
    No input file specified.
    I think this is being generated by apache, the code I'm using doesn't (well shouldn't) produce this flavour of error.

    I tried to use acceptpathinfo, but get a 500 internal server error. I'm not 100% certain on the apache version so it's either my implementation of the example, or my version. Have to check up on that.

    That flag is great, I can see it re-directing to the correct page (I've tried both real path, and the path to the symbolic link I created).

    E.g:

    http://mysite.com/example

    redirects to

    http://mysite.com/index.php/example

    The script only actually runs however, when I use:

    http://mysite.com/index.php

    Nothing else will work at the moment.

  11. #11
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    512
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No input file specified.

    Isn't it coming from PHP?
    If so, there is something wrong with your php setup.

    You are using php-cgi and not putting Action directive, or something like that.
    Freebie/DonationWare: check-these.info
    Custom solutions: Hostwick.com

  12. #12
    SitePoint Guru LinhGB's Avatar
    Join Date
    Apr 2004
    Location
    Melbourne, Australia
    Posts
    902
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're not getting any inputs because AcceptPathInfo is not enabled. For that to work, you need two things (from docs):

    1. Apache 2.0.30 or higher
    2. AllowOverride FileInfo at higher levels

    If you're using Apache 1.3 then there's a different trick but I forget what it is, so check the 1.3 docs.
    "I disapprove of what I say,
    but I will defend to the death my right to say it."

  13. #13
    SitePoint Enthusiast ironikart's Avatar
    Join Date
    Apr 2005
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Crap, yeah it's 1.3.33 - the host is lagging behind in php 5 version upgrades as well (although not related to the scripts I'm running).

    I'll have a hunt around in the docs and see what I can find. Thanks LinhGB

    @extras - I'm 100% certain it's not the php app reporting this, I've done some testing on this.

  14. #14
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Also,

    RewriteRule !^/*(__|index\.php) index.php%{REQUEST_URI} [L] makes the extension for index.php/path/to/request.extension and that doesn't make any sense at all! Perhaps a ? before the %{REQUEST_URI} might help?

    Regards,

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

  15. #15
    SitePoint Enthusiast ironikart's Avatar
    Join Date
    Apr 2005
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    index.php/path/to/request
    that's exactly the string that I want - the script interprets $_SERVER['PHP_SELF'], so that url is perfectly ok. It's working like that in it's current state (ie the URL), but it's not running the appropriate php script.

    I can't find any doco on getting AcceptPathInfo working in apache 1.3.x unfortunately - anyone got any bright ideas?

  16. #16
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    iron,

    Have you tried the Options +MultiViews (or did I miss that in an earlier post)?

    Regards,

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

  17. #17
    SitePoint Enthusiast ironikart's Avatar
    Join Date
    Apr 2005
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've added it, still no joy - terribly frustrating issue that could be solved by the host upgrading apache, but I don't think I'll see that any time soon.

  18. #18
    SitePoint Guru LinhGB's Avatar
    Join Date
    Apr 2004
    Location
    Melbourne, Australia
    Posts
    902
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a similar CMS to mysource matrix:

    http://ez.no/doc/ez_publish/technica...l_host_example

    That Vhost conf works for 1.3. What you need to look at is how to handle PATH_INFO in Apache 1.3. What's also important is whether your PHP is running as a CGI or as Apache module. If I remember correctly, if it's CGI, you're out of luck.

    Btw if you're really running MySource Matrix, forget a shared webhosting account. Think big fat dedicated server(s).
    "I disapprove of what I say,
    but I will defend to the death my right to say it."

  19. #19
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    512
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the PHP needs PATH_INFO, it means it's running as CGI, IMO.

    Then you need to set Action directive, most probably.
    AddType application/x-httpd-php .php
    # replace with the correct path (from document root).
    Action application/x-httpd-php "/php/php.exe"
    Freebie/DonationWare: check-these.info
    Custom solutions: Hostwick.com

  20. #20
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    512
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, PHP-cgi (4 or 5) can be installed in your own directory.
    We've tested that on site5 when they were not supporting php5, yet.

    You may have to compile it at home using same (or similar) OS and with the same directory structure, though.
    Freebie/DonationWare: check-these.info
    Custom solutions: Hostwick.com

  21. #21
    SitePoint Enthusiast ironikart's Avatar
    Join Date
    Apr 2005
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Btw if you're really running MySource Matrix, forget a shared webhosting account. Think big fat dedicated server(s).
    It's been done before, trust me on that one. I'm using an older version 3.2.2, which supports MySQL and has been installed on shared hosts with apache 2.x. I manage several dedicated installations of matrix, but haven't managed to come up with a solution for running a personal site with it.

    @extras, thanks for the advice. I'd have to setup a debian system to run that, so I'm getting into the realm of 'is it worth the trouble?'. Great workaround though.

  22. #22
    SitePoint Guru LinhGB's Avatar
    Join Date
    Apr 2004
    Location
    Melbourne, Australia
    Posts
    902
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, I was thinking of recent MySource Matrix.

    Quote Originally Posted by extras
    If the PHP needs PATH_INFO, it means it's running as CGI, IMO.
    Nope, it's almost the opposite. PHP running as apache module will take these:

    http://example.com/articles/foo-bar

    or

    http://example.com/index.php/articles/foo-bar

    but PHP running as CGI won't accept those sorts of path_info. Instead, it likes this:

    http://example.com/index.php?/articles/foo-bar
    "I disapprove of what I say,
    but I will defend to the death my right to say it."

  23. #23
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    512
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LinhGB,

    I just tested with PHP running with cgi, and with CGI.

    env.php
    PHP Code:
    <pre><? print_r($_SERVER); ?>
    http://example.com/env.php/asd/wrw

    [QUERY_STRING] =>
    [REQUEST_URI] => /env.php/asd/wrw
    [SCRIPT_NAME] => /env.php
    [PATH_INFO] => /asd/wrw

    At least on PowWeb server, it seems to work, just like normal CGI.

    env.cgi
    Code:
    #!/bin/sh
    echo
    printenv|sort
    http://example.com/env.cgi/asd/wrw
    QUERY_STRING=
    REQUEST_URI=/env.cgi/asd/wrw
    SCRIPT_FILENAME=/www/X/X/XXXXX/htdocs/env.cgi
    SCRIPT_NAME=/env.cgi
    Freebie/DonationWare: check-these.info
    Custom solutions: Hostwick.com

  24. #24
    SitePoint Guru LinhGB's Avatar
    Join Date
    Apr 2004
    Location
    Melbourne, Australia
    Posts
    902
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interesting. I'll get back to you on that.
    "I disapprove of what I say,
    but I will defend to the death my right to say it."

  25. #25
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb

    I know this post is old, though for the benefit of anyone that comes across this page, I found the equivalent to doing the alias rule in .htaccess (since apache states that you cannot in the documentation [unable to post url]) is to use the RewriteRule method.

    So if you wanted to do this
    Code:
    alias /old-folder /new-folder
    With RewriteRule, which you place at the top of your .htaccess (or before any other RewriteRules), you would have
    Code:
    RewriteRule /old-folder /new-folder [PT]
    The [PT] flag is to Pass Through the rule, which basically means that the URL which is used by the system becomes changed as if the user had put in the new url themselves.

    If your RewriteRule fails, check that the
    1. apache module is installed
    2. is enabled via
      Code:
      RewriteEngine On
      ; and
    3. correct syntax is used (as it uses regular expressions)


    Hope it helps your question.


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
  •