Changing .htaccess with PHP - removing rewrite rule

Hey guys, a little question.

I use PHP to delete / add static pages after deleting the page, I want to remove it from .htaccess, however I tried this, but it causes an error:

Warning : preg_replace () [function.preg-replace]: Unknown modifier '\' in ...

The code:

$page_name = $row['page_name']; // Example:  help

preg_replace('/RewriteRule ' . preg_quote('^' . $page_name . '/?$ page.php?mode=') . '.*/i', '', $htaccess);

This is an example of what it should completely remove:

RewriteRule ^help/?$ page.php?mode=help
+3
source share
2 answers

You need to exit the expression delimiter by passing it preg_quoteas the second argument.

preg_replace('/RewriteRule ' . preg_quote('^' . $page_name . '/?$ page.php?mode=', '/') . '.*/i', '', $htaccess);

Or else your / will not be escaped. As stated in the documentation, "special regular expression characters:. \ + *? [^] $ () {} =! <> |: -"

+2
source

preg_replace ( "~~ msi", " " ). - - - !!!

foreach ( (.htaccess) $line)
{

, }

, .htaccess...

0

All Articles