how to get rid of /index.php/ in short URLs (dirty hack for now) [repost]

Chris Dudley <[email protected]> Mon, 12 May 2003 13:51:33 +0100
Newsgroups gmane.comp.cms.xaraya.knowledge-base
Organization Xaraya News Server
Message-ID <[email protected]>
From: [email protected] (mikespub)
If you have an Apache webserver with mod_rewrite enabled, here's how
you can get rid of the /index.php/ part in short URLs :
                                                                                
1) in your xaraya home directory, use a .htaccess file with the
following mod_rewrite directives :
                                                                                
# turn mod_rewrite on for this directory
RewriteEngine on
# don't rewrite anything that starts with index.php
RewriteRule ^index\.php - [L]
# don't rewrite anything that ends with .jpg, .gif, .png, .css, .js
(customize)
RewriteRule \.(jpg|gif|png|css|js)$ - [L]
# rewrite everything else
RewriteRule ^(.+) index.php/$1 [L]
                                                                                
You can achieve the same thing with RewriteCond - I'm not
sure if it makes any difference, really. And of course, you
can put similar lines in your httpd.conf file if you're the admin.
 
If anyone can give an equivalent mapping for IIS or other
web servers, be my guest :)
 
2) in includes/xarServer.php, adapt xarServerGetBaseURI to
return only the top-level directory where Xaraya is installed,
no matter what kind of short URLs you'll be using :
 
function xarServerGetBaseURI()
{
    // if your site is at http://www.yoursite.com/xaraya/...
    return '/xaraya';
    // if your site is at http://www.yoursite.com/...
    //return '';
    // ignore the original code - yes, this is a dirty hack :)
    ...
}
 
3) in includes/xarMod.php, adapt xarModURL to drop
the index.php/ part :
 
function xarModURL( ... )
{
   ...
            //return xarServerGetBaseURL() . 'index.php' . $path;
            // remove the leading / from the short URL path
            $path = preg_replace('/^\//','',$path);
            // put everything together for the complete URL
            return xarServerGetBaseURL() . $path;
   ...
}
 
Some of this might end up being configurable, if there's enough
interest for this URL hack :)
 
Mike.