a night of mod_rewrite
i spent the majority of my night (hours, literally) trying to get urls in my editplus wiki that had looked like this:
http://www.editplus.info/index.php/Main_Page
to look like this:
http://www.editplus.info/Main_Page
which required digging into apache’s complex mod_rewrite module and plodding through some really crappy documentation on setting up the rewrite rules to work with mediawiki.
i think i got it working right, but took some doing. then i thought i’d try to improve the mediawiki documentation, but i started having trouble getting the rewrite rules to work in an .htaccess file (i had done everything in httpd.conf), so i just gave up.
update:
here are my mod_rewrite rules for a mediawiki wiki, which are inside a VirtualHost container in Apache’s httpd.conf file:
# Allow rewriting URLs
RewriteEngine on
#RewriteLog /home/jwatt/rewrite.log
#RewriteLogLevel 4
# fix for URLs like this: hostname.tld/?title=page_title
# if the requested page is the root page "/"
# and the query string contains the title
# return the index page, query string will be automatically appended
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{QUERY_STRING} ^title=
RewriteRule ^.*$ /index.php [L,QSA]
# Don't rewrite requests for files in MediaWiki subdirectories,
# MediaWiki PHP files, HTTP error documents, favicon.ico, or robots.txt
RewriteCond %{REQUEST_URI} !/(stylesheets|images|skins)/
RewriteCond %{REQUEST_URI} !/(redirect|texvc|index).php
RewriteCond %{REQUEST_URI} !/error/(40(1|3|4)|500).html
RewriteCond %{REQUEST_URI} !/favicon.ico
RewriteCond %{REQUEST_URI} !/robots.txt
# Rewrite http://wiki.domain.tld/article properly, this is the main rule
RewriteRule ^/(.*) /index.php/$1 [L,QSA]
for the last month, it’s worked for me flawlessly.
mod_rewrite is magic.
Say, I am wondering if you figured out how to get the htaccess working?
If not, can you explain the “virtual host container” in which you have access to httpd.conf ?
Cool site too!
Tim
Tim, the mediawiki documentation strongly suggests that you settle for URLs of the following format:
http://www.example.com/wiki/Article_Namewhich is described on their installation page entitled Eliminating index.php from the url
A virtual host container in an Apache httpd.conf
file looks like this:
<VirtualHost *>ServerName www.domain.tld
DocumentRoot /www/domain
</VirtualHost>
More information on this is available here: Name-based Virtual Host Support
thx 1 thousand times!
Here’s another easier way to accomplish it: http://help.textdrive.com/index.php?pg=kb.page&id=140
I see you went away from using super-short urls. I still try to use it on one of my mediawiki installs. Thanks for the code to not rewrite robots.txt :)