Is it possible to create an .htacess redirect that redirects to "/wiki/if the user forgets it, ie from domain.tld/article to domain.tld/wiki/article? Just a general redirect won't work of course, because the /w/ directory needs to be accessible, but I am so bad when it comes to .htaccess stuff... ;-)
Topic on Project:Support desk
Try adding the following the (untested) code to end of your .htaccess file
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/wiki/$1
Thanks, that always redirects to the wiki's main page instead of just adding the /wiki/ if someone forgets it.
It should also redirect yourwiki.com/GiveMeAPrefix to yourwiki.com/wiki/GiveMeAPrefix.
It doesn't? You can try it at my wiki: https://mariowiki.net/Mario redirects to the main page instead of to https://mariowiki.net/wiki/Mario .
In my .htaccess only the general https redirect comes after your rule.
If you have something after my rule, then you should add [L]
to the end of the RewriteRule line so that none of the other rules are executed.
Still only redirects to main page.
Current .htaccess is:
## http://www.mediawiki.org/wiki/Manual:Short_URL/Apache # Enable the rewrite engine RewriteEngine On # Short URL for wiki pages RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L] # Redirect / to Main Page RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L] RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/wiki/$1 [L] ############HTACCESS W4Y START############ Order Allow,Deny Allow from all <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} mariowiki.net RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] </IfModule> #############HTACCESS W4Y END#############
The message above me was mine, I didn't notice that I got logged out, sorry.
Ok, thanks for posting that.
This is what I've tested and found works:
RewriteCond %{REQUEST_URI} !^/wiki/ RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d RewriteRule ^/?(.*)$ /wiki/$1 [R=301,L]
yes, that does work. Thank you!
I just noticed that there's still a minor problem: entering the domain without https:// or just http:// (example: mariowiki.net/wiki/Mario, mariowiki.net/Mario or http://mariowiki.net/wiki/Mario), it always redirects to the main page (happens to both cases, with /wiki/ and without it), and not to the article in question. Is it possible to fix that? As our wiki was http only until I took it over and moved it to my server last week, there are still loads of http links to it floating around. Can anyone help me?
Current .htaccess is
## http://www.mediawiki.org/wiki/Manual:Short_URL/Apache # Enable the rewrite engine RewriteEngine On # Short URL for wiki pages RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L] # Redirect / to Main Page RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L] RewriteCond %{REQUEST_URI} !^/wiki/ RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d RewriteRule ^/?(.*)$ /wiki/$1 [R=301,L] ############HTACCESS W4Y START############ Order Allow,Deny Allow from all <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} mariowiki.net RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] </IfModule> #############HTACCESS W4Y END#############
Try this replacement:
## http://www.mediawiki.org/wiki/Manual:Short_URL/Apache
# Enable the rewrite engine
RewriteEngine On
# Move to https
RewriteCond %{HTTP_HOST} mariowiki.net
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Short URL for wiki pages
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]
# Redirect / to Main Page
RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]
# Redirect "forgot wiki"
RewriteCond %{REQUEST_URI} !^/wiki/
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?(.*)$ /wiki/$1 [R=301,L]
Thank you very much, that fixes the problem with non-https:// URLs, but forgetting both https and /wiki (like http://mariowiki.net/Mario) still redirects to the main page, but is that even fixable?
When I click your link to http://www.mariowiki.net/Mario I end up on https://www.mariowiki.net/wiki/Mario -- maybe you fixed it already?