suntracker Posted June 11, 2008 Share Posted June 11, 2008 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 More sharing options...
DarkWater Posted June 11, 2008 Share Posted June 11, 2008 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 https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-563463 Share on other sites More sharing options...
suntracker Posted June 11, 2008 Author Share Posted June 11, 2008 Hmm that looks to be promising -- do you know if it's compatible with IE 6 and up? Thanks! Link to comment https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-563487 Share on other sites More sharing options...
DarkWater Posted June 11, 2008 Share Posted June 11, 2008 It's an Apache thing, and it just sends a redirect header, so it should work. Add this to a .htaccess file in your root site directory. Link to comment https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-563490 Share on other sites More sharing options...
suntracker Posted June 11, 2008 Author Share Posted June 11, 2008 Darn, I get an Internal Server Error. I wonder if the server allows .htaccess files... I put it in /httpdocs/.htaccess.. Link to comment https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-563520 Share on other sites More sharing options...
DarkWater Posted June 11, 2008 Share Posted June 11, 2008 Wait. Do you use IIS or Apache? Link to comment https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-563521 Share on other sites More sharing options...
suntracker Posted June 11, 2008 Author Share Posted June 11, 2008 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 More sharing options...
suntracker Posted June 11, 2008 Author Share Posted June 11, 2008 Ah, I've narrowed it down. It doesn't like the second rule you gave me. Link to comment https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-563528 Share on other sites More sharing options...
DarkWater Posted June 11, 2008 Share Posted June 11, 2008 RewriteRule ^mediawiki/index.php/(.+)/$ index.php/?wiki=$1 [R=301,L] Make that the second rule. I threw in an extra ) by accident. Link to comment https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-563529 Share on other sites More sharing options...
suntracker Posted June 12, 2008 Author Share Posted June 12, 2008 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 More sharing options...
DarkWater Posted June 12, 2008 Share Posted June 12, 2008 Try changing the rules to: 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-563542 Share on other sites More sharing options...
suntracker Posted June 12, 2008 Author Share Posted June 12, 2008 no dice :[ This isn't very easy! I'm actually having trouble including the mediawiki page to even render in the <div>... the funny thing is that it works fine under a regular wiki, but not with my modified skin. Link to comment https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-563550 Share on other sites More sharing options...
suntracker Posted June 12, 2008 Author Share Posted June 12, 2008 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 More sharing options...
DarkWater Posted June 12, 2008 Share Posted June 12, 2008 Ha, forgot about that. Good job. Glad I could help. =) P.S: Sorry I wasn't here to respond before, lol. I needed to write a 2 page essay in Greek. >_> Link to comment https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-563564 Share on other sites More sharing options...
suntracker Posted June 12, 2008 Author Share Posted June 12, 2008 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 More sharing options...
DarkWater Posted June 12, 2008 Share Posted June 12, 2008 Are you SURE it has nothing to do with the htaccess stuff? =P And yeah, it's not fun. I finished though. =P Link to comment https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-563575 Share on other sites More sharing options...
suntracker Posted June 12, 2008 Author Share Posted June 12, 2008 Ah, nevermind. When i'm doing the php include it needs the full address (include 'http://foo.com/mediawiki/index.php?title='.$_GET['wiki'] phew! Link to comment https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-563578 Share on other sites More sharing options...
suntracker Posted June 12, 2008 Author Share Posted June 12, 2008 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 More sharing options...
suntracker Posted June 12, 2008 Author Share Posted June 12, 2008 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 More sharing options...
suntracker Posted June 12, 2008 Author Share Posted June 12, 2008 This is a good resource: http://httpd.apache.org/docs/1.3/misc/rewriteguide.html Link to comment https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-564076 Share on other sites More sharing options...
suntracker Posted June 12, 2008 Author Share Posted June 12, 2008 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 More sharing options...
DarkWater Posted June 12, 2008 Share Posted June 12, 2008 That's because you have it set to ?test= instead of ?title=. Link to comment https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-564329 Share on other sites More sharing options...
suntracker Posted June 12, 2008 Author Share Posted June 12, 2008 Nah, I just miswrote it in my post. It is title in my file. Link to comment https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-564336 Share on other sites More sharing options...
DarkWater Posted June 12, 2008 Share Posted June 12, 2008 You can leave the $ on the end of the regex, btw, because it's ending with "any character" (.) anyway. Link to comment https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-564339 Share on other sites More sharing options...
suntracker Posted June 12, 2008 Author Share Posted June 12, 2008 This is my most recent concoction and still no dice: RewriteRule ^mediawiki/index.php?title=(.+)&action=(.+)$ index.php?wiki=$1&action=$2 [R=301] Link to comment https://forums.phpfreaks.com/topic/109796-link-hijacking/#findComment-564366 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.