not working when drupal is installed in a subdirectory

WiseTeck - September 4, 2008 - 17:00
Project:Global Redirect
Version:HEAD
Component:Code
Category:bug report
Priority:critical
Assigned:nicholasThompson
Status:needs work
Description

the fix for Admodule http://drupal.org/node/278199 introduce a new bug. This solution will not work if drupal is installed in subdirectory (eg: htdocs/subfolder/drupal/ ).
In this case the value for $_SERVER['SCRIPT_NAME'] is not 'index.php', but /subfolder/drupal/index.php.
This small patch will fix it.

AttachmentSize
globalredirect-subdirectory.patch631 bytes

#1

nicholasThompson - September 5, 2008 - 11:22
Priority:normal» critical
Assigned to:WiseTeck» nicholasThompson
Status:needs review» needs work

This is a good point...

My concern here is if someone (stupidly) calls their nested bootstrap index.php, then this patch will cause issues too.

So, lets take a look at the opions... Drupal could be installed in:

  • /index.php
  • /subfolder/index.php

Based on these two scenarios, the modules could then have a bootstrap in...

  • /sites/all/modules/mymodule/ad.php
  • /subfolder/sites/all/modules/mymodule/ad.php

Your patch solves these issues, but what if a developer releases a module with a bootstrap as...

  • /sites/all/modules/mymodule/index.php
  • /subfolder/sites/all/modules/mymodule/index.php

So essentially - for a given Drupal Install, what's the difference between these two paths?

  • /subfolder/index.php
  • /subfolder/sites/all/modules/mymodule/index.php

The latter could (POSSIBLY) be an install of drupal which happens to be nested 6 levels down.

This problem is unlikely and very edge case but I cant help but think there must be a very elegant solution for this!

#2

WiseTeck - September 9, 2008 - 16:04

Yeah, got your point. The ambiguity between

  • /subfolder/index.php
  • /subfolder/sites/all/modules/mymodule/index.php

could be solved by using base_path()

If /subfolder/sites/all/modules/mymodule/index.php would be a nested 6 level drupal setup then the base_path would be '/subfolder/sites/all/modules/mymodule/'

so the test should be

if ($_SERVER['SCRIPT_NAME'] != base_path().'index.php') return false;

#3

nicholasThompson - September 14, 2008 - 23:22

WiseTeck... Not quite... base_path() simply represents the path that the script was called in. It could be root or it could be a module.

I believe the way the Ad module gets around this is to, upon install, store in a variable the location of module itself. This allows it to compare the current URL to the "known" module location.

I'm wondering if this could be a feature of the new globalredirect admin I've added to 5.x-dev... By default the ONLY URL which should have redirects is base_path() . 'index.php' and this is decided upon module install/update. In the admin area, the site admin can control the paths which ARE allowed to be redirected upon...

#4

gielfeldt - October 5, 2008 - 09:08

what about storing the base_path() during installation of the module?

like this:
variable_set('globalredirect_base_path', base_path());

and then in the hook:
$base_path = variable_get('globalredirect_base_path', base_path());
if ($_SERVER['SCRIPT_NAME'] != $base_path.'index.php') return false;

anyone see any problems with this?

#5

nicholasThompson - October 6, 2008 - 09:24

gielfeldt: Seems like a sensible solution...

#6

David Lesieur - December 17, 2008 - 16:16
 
 

Drupal is a registered trademark of Dries Buytaert.