Skip to content
Advertisement

Altering .htaccess with PHP – removing a rewrite rule

I am using PHP to remove/add static pages once a page has been deleted, I want to be able to remove it from the .htaccess, however I’ve tried this, but it throws an error:

Warning: preg_replace() [function.preg-replace]: Unknown modifier ” in …

The code:

JavaScript

This is an example of what it should fully remove:

JavaScript

Advertisement

Answer

You have to escape the expression delimiter by passing it to preg_quote as the second argument.

JavaScript

Or else your / won’t be escaped. As stated in the documentation “the special regular expression characters are: . + * ? [ ^ ] $ ( ) { } = ! < > | : -“

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement