Talk:Eliminating index.php from the url/Sy's mod rewrite rules

Latest comment: 15 years ago by 195.128.121.21 in topic Thank You,

A note to readers: I don't maintain this page, but I do maintain similar notes on my own site. See http://jrandomhacker.info/Mod_rewrite


I have moved my wiki into a subdirectory, and so I can no longer use these exact rules. I will have to revisit the rules to work with a subdirectory, because minor playing with these rules didn't work for me.

I spent far too much time playing around with something which should be properly documented. Many of the other suggestions are broken to one degree or another, so I've been trying to integrate all that experience into something that would actually work for me. My goal is still to make one proper set of instructions appropriate for everyone interested. We need to obsolete all of those old notes. This is nuts.

Finally, the rules work as expected! Are there other things I didn't account for? Are there other entries I can add to the "testing" section? If you can help, especially if you can modify these rules with ones that work, please please email me so I can use those changes. (sy1234 at gmail)


I'm especially interested in making this universal for both those who use / and who use /wiki

-- Sy / (talk) 10:54, Mar 3, 2005 (UTC)

Mine reports this:

If your numbers are different, especially your MediaWiki version, things may work a bit differently for you. Don't despair.. try things out and if they don't work come chat and we'll work on the problem together.

I don't use localhost/mediawiki/Main_Page or localhost/wiki/Main_Page or the like.. just localhost/Main_Page. This means that I changed references to /wiki to / and also customised my wgArticlePath:

$wgArticlePath = "/$1";

modify apache's httpd.conf

Many installations have this done for you by default. To be safe, search for "rewrite" in your httpd.conf and uncomment the line which looks something like:

LoadModule rewrite_module modules/mod_rewrite.so

Append the following to the bottom of your httpd.conf:

# Allow rewriting URLs
RewriteEngine on

# If using a subdirectory like htdocs/wiki/  Not necessary when the wiki is in htdocs/ (i.e. the root)
# RewriteBase /wiki


# Don't rewrite requests for these MediaWiki subdirectories and files
# you may need to change "stylesheets" to "skins" (v1.4?)
RewriteCond %{REQUEST_URI} !^/(stylesheets|images)/
RewriteCond %{REQUEST_URI} !^/(redirect|texvc|index).php

# other notible conditions
RewriteCond %{REQUEST_URI} !^/error/(40(1|3|4)|500).html
RewriteCond %{REQUEST_URI} !^/favicon.ico
RewriteCond %{REQUEST_URI} !^/robots.txt


# Make sure there is no query string - unless user is making a search
RewriteCond %{QUERY_STRING} ^$ [OR] %{REQUEST_URI} ^/Special:Search


#I suspect that people who use /wiki will need the following line, but I'm not sure:
#RewriteCond %{REQUEST_URI} ^/wiki$

# Rewrite URI/foo properly, this is the main rule.
RewriteRule ^(.*)$ /index.php$1 [L,QSA,NE]		# Quirk: Truncates question marks (%3F)
#RewriteRule ^(.*)$ /index.php?title=$1 [L,QSA,NE]	# Fails with ampersands (not tested)

Issues

edit
BUGS
  • Some template links still point to "index.php/foo" and would have to be hand-edited somehow. This includes entries in the sidebar and page tabs.


RFEs
  • the installation directory should be in a variable
  • the "Main_Page" should be in a variable


Quirks

Testing

edit
Start URL Goal URL Current status
http://localhost/ http://localhost/ pass with
http://localhost/Main_Page
http://localhost/Main_Page http://localhost/Main_Page pass
http://localhost/Sandbox http://localhost/Sandbox
(if it exists)
pass
http://localhost/index.php/Special:Search?search=Sandbox http://localhost/Sandbox
(if it exists)
pass
http://localhost/index.php/Special:Search?search=Special:Version http://localhost/Special:Version pass
http://localhost/Special:Randompage http://localhost/Page
(as appropriate)
pass

Thank You,

edit

-- User:195.128.121.21 07:15, 29 July 2009 (UTC)Reply

Return to "Eliminating index.php from the url/Sy's mod rewrite rules" page.