Mod Rewrite Exceptions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
tvs008
Forum Commoner
Posts: 29
Joined: Wed May 03, 2006 10:46 pm
Location: Seattle

Mod Rewrite Exceptions

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
tvs008
Forum Commoner
Posts: 29
Joined: Wed May 03, 2006 10:46 pm
Location: Seattle

Post 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. ...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
tvs008
Forum Commoner
Posts: 29
Joined: Wed May 03, 2006 10:46 pm
Location: Seattle

Post 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;
}
??????
User avatar
tvs008
Forum Commoner
Posts: 29
Joined: Wed May 03, 2006 10:46 pm
Location: Seattle

Post 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;
}
User avatar
tvs008
Forum Commoner
Posts: 29
Joined: Wed May 03, 2006 10:46 pm
Location: Seattle

Post 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...
Post Reply