1 Online. Join themUsers

Search

For a plugin I’m writing I need to add a few lines to the .htaccess file. Unfortunately, I need to access the rewritebase.

Since that is not possible, I was wondering whether I can set an environmental variable, and set the rewritebase and my rule using that var.

Unfortunately, all my attempts have failed.. :(

I think it’s easiest for me to explain what I’m trying to do, if I “ported” it to php:

$this->base = '/symphony';
$this->rewrite_base = $this->base;
$this->custom_rule = $this->base . 'my own rules';

Thanks!

Take a look at this – it is right from the JIT extension:

    public function install(){

        $htaccess = @file_get_contents(DOCROOT . '/.htaccess');

        if($htaccess === false) return false;

        ## Cannot use $1 in a preg_replace replacement string, so using a token instead
        $token = md5(time());

        $rule = "
### IMAGE RULES 
RewriteRule ^image/(.+.(jpg|gif|jpeg|png|bmp))$ extensions/jit_image_manipulation/lib/image.php?param={$token} [L,NC]nn";

        ## Remove existing the rules
        $htaccess = self::__removeImageRules($htaccess);

        if(preg_match('/### IMAGE RULES/', $htaccess)){
            $htaccess = preg_replace('/### IMAGE RULES/', $rule, $htaccess);
        }
        else{
            $htaccess = preg_replace('/RewriteRule .* - [S=14]s*/i', "RewriteRule .* - [S=14]n{$rule}t", $htaccess);
        }

        ## Replace the token with the real value
        $htaccess = str_replace($token, '$1', $htaccess);

        return @file_put_contents(DOCROOT . '/.htaccess', $htaccess);

    }

If you are writing to the .htacces file, please don’t forget the uninstall procedure… You will find example code in the JIT extension as well.

Maybe I have not really understood what you are trying to achieve. Couldn’t it work like the JIT example, using relative paths?

Yeah, I already noticed that, pretty clever.

The only option I see right now is to read the current value of RewriteBase using php, then using that value in my new rewriterule.

I’m trying to redirect all heavy files to the coral network to save on bandwidth Unfortunately, this means I have to rewrite my urls from http://www.host.com/base/urls to http://www.host.com.nyud.net/base/urls

That’s where the rewritebase kicks in. All the rules in the symphony htaccess file are based on the rewritebase, but since I need to edit the entire URL, I can’t..

It’s hard to explain… kindof… `

Login to Comment

Symphony • Open Source XSLT CMS

Server Requirements
  • PHP 5.2 or above
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 4.1 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts