Jump to content

Link 'Hijacking'


suntracker

Recommended Posts

Hi. I don't know if this is possible but I hope it is...

 

I'm building a website which requires that some pages are editable via a wiki-like system.

I installed mediawiki, which is located at /httpdocs/mediawiki (the rest of the website resides in /httpdocs/

 

Now, I can render any single page of the wiki into the central column of the website using a php include, BUT any link within that wiki page naturally tries to take the user to something like:

http://foo.com/mediawiki/index.php/LINK

 

Is it possible to 'hijack' that link so that whenever anybody wishes to navigate to other wiki pages, it alters it to something like:

http://foo.com/index.php/?wiki=LINK (effectively removing the /mediawiki/ component of the address)

 

I don't really know how to go about this.

I've heard of people using a wiki and creating a 'normal' looking website out of it, but a majority of the funtionality and content for this site is not really wiki-based so I don't think I can go to that extreme.

 

Thanks for any assistance!

-Austin

Link to comment
Share on other sites

You can try a mod_rewrite thing:

 

RewriteEngine On

RewriteRule ^mediawiki/index.php/(.+)$ index.php/?wiki=$1  [R=301,L]

RewriteRule ^mediawiki/index.php/(.+))/$ index.php/?wiki=$1  [R=301,L]

 

EDITED: Forgot to add the redirects.

 

Link to comment
Share on other sites

It's Apache.

 

I learned that I need to put Options +FollowSymlinks before I try and turn the rewrite engine on, but it still threw the error.

 

I haven't been using an .htaccess file before now so I removed the two rules:

RewriteRule ^mediawiki/index.php/(.+)$ index.php/?wiki=$1  [R=301,L]

RewriteRule ^mediawiki/index.php/(.+))/$ index.php/?wiki=$1  [R=301,L]

 

And can access the site again.

Maybe it's the R=301?

 

 

Link to comment
Share on other sites

Ah, that fixed it. Server doesn't complain anymore.

 

Now I've run into another issue...

 

When I click a link in the wiki, like "http://beta2.armyproperty.com/mediawiki/index.php/LINK"

the .htaccess forms the following:

"http://beta2.armyproperty.com/var/www/vhosts/armyproperty.com/subdomains/beta2/httpdocs/index.php/?wiki=LINK"

 

Obviously the /var/www/vhosts/armyproperty.com/subdomains/beta2/httpdocs/" shouldn't be there...

Other than that, it's neat .htaccess rewrite rules are so powerful.

 

Thanks for sticking with me in the thread to help.

Link to comment
Share on other sites

Ah-Ha!

 

I added RewriteBase / after the RewriteEngine On line:

 

The working .htaccess file is now:

 

Options +FollowSymlinks

RewriteEngine On

RewriteBase /

RewriteRule ^mediawiki/index.php/(.+)$ index.php/?wiki=$1  [R=301]

RewriteRule ^mediawiki/index.php/(.+)/$ index.php/?wiki=$1  [R=301]

 

Link to comment
Share on other sites

That sounds not fun.

 

So it *almost* works now.

 

Strangely, if I try and include a page on a mediawiki installation that's installed on the same subdomain as the website I'm working on, it doesn't work.

BUT if I use a different mediawiki installation on a different subdomain, it works!

I have no idea why.

 

This has nothing to do with the .htaccess stuff but it's still puzzling.

Link to comment
Share on other sites

Alright, I've been making progress.

 

One thing I've noticed, though: If you want to edit a page, it forms a different kind of link:

http://foo.com/mediawiki/index.php?title=Main_Page&action=edit

 

So instead of the index.php/Main_Page format, I have to deal with ?title=*&action=*

 

I tried to make another .htaccess rule, but it doesn't work :[

 

I've tried these:

RewriteRule ^mediawiki/index.php(.+)$ index.php?wiki=$1  [R=301]

RewriteRule ^mediawiki/index.php?title=(.+)$ index.php?wiki=$1  [R=301]

 

I even tried just taking ANY /mediawiki address and rewriting it... would this be the best option?

RewriteRule ^mediawiki/(.+)$ index.php?wiki=$1  [R=301]

Link to comment
Share on other sites

Here is how I need to be able to rewrite things:

 

 

Change:

http://foo.com/mediawiki/index.php?title=Main_Page

To:

http://foo.com/index.php?wiki=Main_Page

 

---

 

Change:

http://foo.com/mediawiki/index.php/Main_Page

To:

http://foo.com/index.php?wiki=Main_Page

 

---

 

Change:

http://foo.com/mediawiki/index.php?title=Main_Page&action=edit

To:

http://foo.com/index.php?wiki=Main_Page&action=edit

 

 

I've looked around on documentation on the whole mod rewrite issue and the syntax is so confusing.

I'll keep reading..

 

Link to comment
Share on other sites

I guess I don't understand why I can't just remove the $ so it takes the rest of the URL along with it...

RewriteRule ^mediawiki/index.php?title=(.+) index.php?wiki=$1  [R=301,L]

 

Wouldn't that take everything after php?title= and put it in $1?

 

so if it was index.php?title=FOO&action=BAR it would result in index.php?wiki=FOO&action=BAR ??

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.