3 Replies - 294 Views - Last Post: 11 January 2013 - 01:32 AM Rate Topic: -----

#1 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 801
  • View blog
  • Posts: 1,700
  • Joined: 30-January 09

Get Apache rewritten URL

Posted 10 January 2013 - 04:41 PM

I've got a problem with my site due to an SEO mod I installed for my forums software, which generates a long set of RewriteRules for .htaccess. By and large, the site is fine, but if I navigate to a forum board nested more than 1 level deep (i.e. a subforum) then the root-pathing algorithm I use doesn't accurately hit the actual root of the site, as it doesn't prepend '../' enough times to the root path variable. This is problematic because the pathing constants that I define in the code are used equally for file inclusion (internally in PHP) as they are for parameterising URL paths for images, css files, scripts, etc (in HTML). I have narrowed it down to the fact that the RewriteRules are creating a URL that has a different nesting level to the unwritten path.

Is there a way to determine (in PHP) the URL of a page after it has been rewritten by Apache RewriteRules? If I can get the rewritten URL, then I'm fine and dandy, otherwise, I'm going to have to figure out a better pathing method for the site ://>/>

This post has been edited by e_i_pi: 10 January 2013 - 04:43 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Get Apache rewritten URL

#2 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 928
  • View blog
  • Posts: 3,212
  • Joined: 19-January 10

Re: Get Apache rewritten URL

Posted 10 January 2013 - 05:22 PM

Can you add your own rewrite rule that directs towards the php files?

something that would rewrite something like dev/thedir/thefile.php to /thedir/thefile.php

RewriteRule ^(dev/[a-zA-Z-]*.php)$ $1.php [QSA,L]


That's a random guess, it probably doesn't work, but it's just to convey what I mean. So with this all you'd have to do is add "dev/" onto all of your includes.

I may be wrong though and going about this the wrong way though, so apologies if this is wrong.

edit: lol... analogies.

This post has been edited by creativecoding: 11 January 2013 - 02:55 PM

Was This Post Helpful? 1
  • +
  • -

#3 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 801
  • View blog
  • Posts: 1,700
  • Joined: 30-January 09

Re: Get Apache rewritten URL

Posted 10 January 2013 - 06:30 PM

Hmm, just did another search around the net (I have been working on this for days), and it looks like there is a variable $_SERVER['REDIRECT_URL']. It would be handy if that was mentioned somewhere in the PHP Manual :sigh: I still have to test this at home, but it looks like that might be the answer.
Was This Post Helpful? 0
  • +
  • -

#4 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 801
  • View blog
  • Posts: 1,700
  • Joined: 30-January 09

Re: Get Apache rewritten URL

Posted 11 January 2013 - 01:32 AM

Solved it, I had to map out the URI paths separately to the include paths, which is a pain for me to fix up all my code, but at least it's a solution. For anyone who's interested, here's the code that I used. You may need to tweak the $nested_level for your site depending on where your root directory lies in relation to the directory structure of the entire site:
// Map out the site root path, used for PHP includes
$nested_level = 5;
$cwd = getcwd();
$PATH_ROOT = './';
for($i = count(explode('\\', $cwd)); $i > $nested_level; $i--)
{
	$PATH_ROOT .= '../';
}
define('PATH_ROOT', $PATH_ROOT);

// Map out the URI root, for file includes (caters for RewriteRule path nesting level changes)
$URI_ROOT = './';
$redirectPath = (array_key_exists('REDIRECT_URL', $_SERVER) ? $_SERVER['REDIRECT_URL'] : $_SERVER['REQUEST_URI']);
for($i = count(explode('/', $redirectPath)); $i > $nested_level - 2; $i--)
{
	$URI_ROOT .= '../';
}
define('URI_ROOT', $URI_ROOT);


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1