Forum Moderators: phranque
My current .htaccess file:
RewriteEngine On
RewriteRule ^wiki/(.*)$ /w/index.php?title=$1 [PT,L,QSA]
RewriteRule ^wiki/*$ /w/index.php [L,QSA]
RewriteRule ^/*$ /w/index.php [L,QSA]
Using this, the URLs like
http://example.net/w/index.php?title=Fringe_Symbols
are being rewritten to
http://example.net/wiki/Fringe_Symbols
OK, that's great. However all old links pointing to the site look like this:
http://example.net/index.php?title=Fringe_Symbols
These all give me a 404 error. I think what I need is another rewrite rule that redirects that to the /w/ dir?
[edited by: jdMorgan at 1:39 am (utc) on Sep. 10, 2009]
[edit reason] example.net [/edit]
Using this, the URLs like
http://example.net/w/index.php?title=Fringe_Symbols
are being rewritten to
http://example.net/wiki/Fringe_Symbols
That's entirely backwards. Client requests for the URL example.net/wiki/Fringe_Symbols are being rewritten to the server filepath /w/index.php?title=Fringe_Symbols as a quick look with Live HTTP Headers will demonstrate.
You'll likely need to use a RewriteCond examining the server variable %{THE_REQUEST} to pick out the query string as well as prevent an 'infinite' rewrite/redirection loop.
Also, I should point out that your second rule above will execute only in the case that wiki is followed by zero or more slashes -- actually, the whole thing looks far more complex than it needs to be. Try:
RewriteEngine on
#
RewriteRule ^wiki/(.*)$ /w/index.php?title=$1 [L]
RewriteRule ^(wiki)?$ /w/index.php [L]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php\?title=([^&\ ]+)\ HTTP/
RewriteRule ^index\.php$ http://example.net/wiki/%1? [R=301,L]
The [PT] flag is only needed when you wish to pass the output from the mod_rewrite rule to another module which requires a URL-path rather than a filepath as input. That's not likely in this case, so don't make extra work by using this flag if it's not needed.
Note that in the new redirect rule, a "?" is appended to the substitution URL to clear the query string. This is not a literal question mark, and it will not appear in the outpur.
THE_REQUEST is the entire client request line, just as it appears in your raw server access log. By testing this line, we assure that the redirect will only be invoked if the dynamic URL-path is requested directly by a client, and not as a result of previously executing one of your internal rewrites. In this way, we prevent the rewrites and the new redirect from countermanding each other and creating an 'infinite' loop.
Jim
Unfortunately, I don't know MediaWiki, so I can't tell you if that query string is formatted correctly or not.
Jim