2

Our site has something like this as our .htaccess

RewriteEngine On
RewriteRule ^/wiki/Main_Page$ /wiki/Welcome_to_Our_Site [R]
RewriteRule ^/?wiki/?$ / [R]

RewriteRule ^/?$ %{DOCUMENT_ROOT}/index.php?title=Welcome_to_Our_Site [L,QSA]
RewriteRule ^/?wiki(/.+)$ %{DOCUMENT_ROOT}/index.php [L]
RewriteRule ^/?w(/.*)?$ %{DOCUMENT_ROOT}/index.php [L]

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&width=$2 [L,QSA,B]

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&width=$2&archived=1 [L,QSA,B]

I have also used MediaWiki:Mainpage to point to Welcome_to_Our_Site.

For the sake of users who may have bookmarked the old page, I would also like Main_Page to manually redirect to Welcome_to_Our_Site--without a redirect notice--but it is not happening.

I originally moved the Main Page to Welcome_to_Our_Site, creating a redirect within the Mediawiki software, but even when I delete the Main Page or add text into it without a redirect, my htaccess rule does not override Mediawiki's own redirecting as I think it should and redirect Main Page to Welcome_to_Our_Site, changing the URL, but without the Mediawiki "(Redirected from Main Page)" redirect text showing up. What is wrong with the line I expect should do the trick RewriteRule ^/wiki/Main_Page$ /wiki/Welcome_to_Our_Site [R] or the cascading after it?

Brett Zamir
  • 14,034
  • 6
  • 54
  • 77

1 Answers1

2

Keep your first 2 rules as this:

RewriteRule ^/?wiki/Main_Page/?$ /wiki/Welcome_to_Our_Site [NC,L,R=302]

RewriteRule ^/?wiki/?$ / [R=302,L,NC]

Assuming this htaccess is placed in site root directory and the there is no .htaccess in /wiki/ directory (if at all that is a directory).

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 1
    +1 for cueing me into the need for `/?` at the beginning. However, it seems I did need my old use of `[R]` as `[NC,L]` did not do the trick. – Brett Zamir Feb 23 '16 at 06:18
  • Yes you can add `R` but then URL in browser will also change to `/wiki/Welcome_to_Our_Site` – anubhava Feb 23 '16 at 06:19
  • I've updated the OP to clarify I wanted it to change the URL. If you want to edit your answer, I'll put yours as the answer. – Brett Zamir Feb 23 '16 at 06:26
  • 1
    @BrettZamir: You *probably* should add a [RewriteBase](http://stackoverflow.com/questions/704102/how-does-rewritebase-work-in-htaccess) directive to your .htaccess file, and get rid of all the `%{DOCUMENT_ROOT}` hacks. (That said, your entire setup looks a little bit funny, especially the `/w/` redirect. I may write a longer answer about this later, if I have time.) – Ilmari Karonen Feb 23 '16 at 06:39
  • And yes `%{DOCUMENT_ROOT}/` can be removed from target URIs even without any `RewriteBase` since those are for internal rewrites only. – anubhava Feb 23 '16 at 06:55