问题
I've implemented Short URL for my mediawiki and I have these in htaccess that works:
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?w/images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/w/thumb.php?f=$1&width=$2 [L,QSA,B]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?w/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/w/thumb.php?f=$1&width=$2&archived=1 [L,QSA,B]
How do I redirect page urls that doesnt have page title to Main_Page? Like redirecting mysite.com/wiki/ to the mysite.com/w/index.php/Main_Page? In the MW Apache rewrite Manual it says this:
Optionally, you can include a rule to show the Main Page on the path itself, to simplify navigation when people visit urls without a page title specified:
# Redirect / to Main Page RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]
When I add the above, the main domain address gets redirected to wiki which I dont want since I have a different Home Page and not wiki. I only want to redirect the address that looks like mysite.com/wiki
I tried this rewrite but it doesnt work.
RewriteRule ^/?wiki/?$ %{DOCUMENT_ROOT}/w/index.php [L]
Obviously I got something wrong. Can someone look at this please?
回答1:
This redirect rule should automatically take care of redirecting urls with no page title like /wiki/ to the wiki/Main_Page too:
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]
It wasnt working for me before since there was other rewrite rules before this. It worked once I move this rewrite rule to the top before all other rewrite rules.
来源:https://stackoverflow.com/questions/18843356/how-to-redirect-mediawiki-short-url-with-no-title-to-main-page