Page 1 of 1

Mod Rewrite Exceptions

Posted: Wed May 03, 2006 10:59 pm
by tvs008
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


The site I'm working on is changing all .php to .html. First of all, why? Second, I am trying to have a page "contact.php" NOT changed to html. How do I create an exception? Below is the code in the footer. (Im not sure I understand why this exists in addition to the REWRITE stuff in the .htaccess file??)  --

Code: Select all

function replace_for_mod_rewrite(&$s)
{
$urlin =
array(
"'(?<!/).php'"
);

$urlout = array(
"$1.html"
);

$s = preg_replace($urlin, $urlout, $s);
return $s;
}

Shoud I make an if ! contact.php { ... } ? Im not really sure how this script is working.
thanks


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]1.[/b] Select the correct board for your query. Take some time to read the guidelines in the sticky topic.[/quote]

Posted: Wed May 03, 2006 11:22 pm
by feyd
It would appear the code you have is designed to alter in-page links proactively by having the script call it with the source code being sent to the user. As for creating an exception, you could use preg_replace_callback() with a function that knows which files to make exceptions for.

Posted: Thu May 04, 2006 1:44 am
by tvs008
thanks feyd for your reply. sorry for breaking so many guidlines on my first post...

I'm checking out preg_replace_callback but I'm a little intimidated thinking I'm going to have to learn regular expressions to create an exception here. ...

Posted: Thu May 04, 2006 9:16 am
by feyd
The callback you specify can perform the check based on data sent in the match results. If done write, you shouldn't need more regex or more complicated regex than pretty much what you have already.

Posted: Thu May 04, 2006 12:12 pm
by tvs008
something like :

Code: Select all

function replace_for_mod_rewrite(&$s)
{
$urlin =
array(
"'(?<!contact).php'",
"'(?<!/).php'"
);

$urlout = array(
"$contact.php",
"$1.html"
);

$s = preg_replace($urlin, $urlout, $s);
return $s;
}
??????

Posted: Thu May 04, 2006 3:18 pm
by tvs008
Actually I got that wrong a bit.

In the footer we have:

Code: Select all

<?
$contents = ob_get_contents(); // store buffer in $contents
ob_end_clean(); // delete output buffer and stop buffering
echo replace_for_mod_rewrite($contents); //display modified buffer to screen
global $dbg_starttime;		
?>
and the _config.php file has the code below. How do I create an exception for one page?

Code: Select all

function replace_for_mod_rewrite(&$s)
{
$urlin =
array(
"'(?<!/).php'"
);

$urlout = array(
"$1.html"
);

$s = preg_replace($urlin, $urlout, $s);
return $s;
}

Posted: Fri May 05, 2006 3:24 pm
by tvs008
Update:: I couldn't figure this one out, so I just created a contact.html page. Duh. Anyway, I tried some if (...) statements, but they didnt work. Really curious what I'm missing here. I don't know if its because I dont know anything about regexpressions or if im missing something simpler...