RE: How do I implement ModRewrite? Getting rid of the index.php
"Michael Cortez" <[email protected]> Mon, 3 Nov 2003 08:16:56 -0800
| Newsgroups | gmane.comp.cms.xaraya.devel,gmane.comp.cms.xaraya.knowledge-base |
|---|---|
| Message-ID | <001801c3a225$ef6fff50$0601a8c0@paxtera> |
>> I have looked though the newsgroup and wonder if I missed
>> something, but how do I utilize ModRewrite in 9.1.3 and up?
>> I have not seen any settings relating to it. Does it just
>> work automagically?
>>
hrm.
Looks like I forgot to commit a message to the knowledge base.
As of, 9.1.4 (actually 9.1.3 + some bk steps I think), there is some direct
support for mod_Rewrite in the base configuration of Xaraya.
Here is are the instructions:
=====================================
How-To get rid of /index.php/ in short URLs (core support BaseURL / BaseURI
/ mod_rewrite)
=============
This is an update that keys off an old post by mikespub that provided
support for using Apache's mod_rewrite to remove the "/index.php/" part of
Xaraya URLs, by hacking some of the Xaraya core files (xarMod.php &
xarServer.php)
The old post is available from the Knowledge Base Mailinglist as a repost by
Chris Dudley, located at:
http://lists.xaraya.com/pipermail/xaraya_knowledge-base/2003-May/000113.
html
This is an example of what using mod_rewrite (on apache, and isapi_rewrite
on IIS) along with the new core configuration variables will allow you to
do:
Current BK, viewing an article:
===============================
Short-URLS not enabled:
http://thefga.com/index.php?module=articles&func=display&aid=18
Short-URLs enabled:
http://thefga.com/index.php/articles/18
Short-URLs enabled, BaseURI/URL defined, and mod_rewrite enabled:
http://thefga.com/articles/18
As you can see, utilizing a defined BaseURI/URL and using Apache's
mod_rewrite, you can shorten your URLs, make them easier to
understand/remember, and simpify log analysis {many apache log packages
don't take URL variables into account and would collapse all index.php?*
pages into requests for a single page, ie index.php}
As outlined in the original post "how to get rid of /index.php/ in short
URLs (dirty hack for now)" you could put into place an .htaccess file in
your web directory, and then manually modify core files within Xaraya to
change the way that short URLs were generated. The problem was that any
time you updated your site, you would need to re-hack your core files.
Troublesome to say the least.
This functionality is now available directly in the core, through four
variables provided in the config.system.php file. These are those four
variables:
$systemConfiguration['AutoDetectBaseURI'] = true; // Defaults to true
$systemConfiguration['BaseURI'] = '/';
$systemConfiguration['AutoDetectBaseURL'] = true; // Defaults to true
$systemConfiguration['BaseModURL'] = 'index.php';
By default, Xaraya will work with an Automagic system that detected the
BaseURI ("http://domain.com/your_web_root") and BaseModURL ("/index.php")of
the system.
However, by setting either AutoDetectBaseURI or AutoDetectBaseURL to FALSE,
you can overide the default behavior of Xaraya and manually specify the
BaseURI and BaseModURL values for your site.
One such example for doing this would be in enabling mod_rewrite.
For mod rewrite you will need to be on an Apache webserver, and have the
mod_rewrite module loaded and availabe, and be allowed to create a .htaccess
file.
Please in the root of your xaraya installation, at the same level as your
index.php file, a .htaccess file with the following mod_rewrite directives :
#============== Begin Mod Rewrite ================== # 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]
#=============== End Mod Rewrite ===================
Then edit your var/config.system.php file and turn off AutoDetect for both
BaseURI and BaseModURL, and specify empty strings for the BaseURI/ModURL
override values: ''
// Approximately lines 54-58 $systemConfiguration['AutoDetectBaseURI'] =
false; $systemConfiguration['BaseURI'] = '';
$systemConfiguration['AutoDetectBaseURL'] = false;
$systemConfiguration['BaseModURL'] = '';
Take care,
--
Michael Cortez
_______________________________________________
Xaraya_developer mailing list
[email protected]
http://lists.xaraya.com/mailman/listinfo/xaraya_developer