Topic on Project:Support desk

Is it possible to redirect if the user forgets the "/wiki"?

14
Semako96 (talkcontribs)

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... ;-)

MarkAHershberger (talkcontribs)

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
Semako96 (talkcontribs)

Thanks, that always redirects to the wiki's main page instead of just adding the /wiki/ if someone forgets it.

MarkAHershberger (talkcontribs)

It should also redirect yourwiki.com/GiveMeAPrefix to yourwiki.com/wiki/GiveMeAPrefix.

Semako96 (talkcontribs)
MarkAHershberger (talkcontribs)

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.

2A02:8388:6982:B700:CC4E:BC56:9C2:A192 (talkcontribs)

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#############
Semako96 (talkcontribs)

The message above me was mine, I didn't notice that I got logged out, sorry.

MarkAHershberger (talkcontribs)

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]
Semako96 (talkcontribs)

yes, that does work. Thank you!

Semako96 (talkcontribs)

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#############
MarkAHershberger (talkcontribs)

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]
Semako96 (talkcontribs)

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?

MarkAHershberger (talkcontribs)