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
https://forums.phpfreaks.com/topic/109796-link-hijacking/
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
https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-563527
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
https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-563537
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
https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-563558
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
https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-563574
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
https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-564026
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
https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-564075
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
https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-564327
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.