3

My previous server working fine.. Today I changed new server and getting RewriteRule cannot compile regular expression on my htaccess.

How to fix this line.

RewriteRule ^category/([0-9]+)(?:/([^/]+)(?:/([^/]+))?)(?:/([^/]+)(?:/([^/]+))?)?/$ ./category.php?pid=$1&catname=$2&page=$3 [L]

Let me know :)

Greg
  • 481
  • 1
  • 5
  • 21
wow
  • 7,989
  • 17
  • 53
  • 63

1 Answers1

7

You are probably using a different Apache version with a different regular expression engine. The Apache versions since 1.3 use POSIX ERE while the versions since 2.0 use PCRE. And only PCRE support the non-capturing group (?:expr).

So try a pattern without them:

RewriteRule ^category/([0-9]+)(/([^/]+)(/([^/]+))?)(/([^/]+)(/([^/]+))?)?/$ ./category.php?pid=$1&catname=$3&page=$5 [L]
Gumbo
  • 643,351
  • 109
  • 780
  • 844
  • It different from [ERE](https://en.wikibooks.org/wiki/Regular_Expressions/POSIX-Extended_Regular_Expressions): `//` [will not match](https://stackoverflow.com/questions/37513946/rewrite-rule-containing-double-slash-not-matched) because you need to act as if there is only a single `/`. But it's a helpful hint (upvoted) for general syntax reference, so thanks! – Luc Jan 13 '23 at 12:23