Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewrite Rule exclude certain strings from (.*) in Regex

I currently have the following htaccess rewrite rule:

RewriteRule    (.*) index.php/$1 [L]

How do I make it exclude 2 certain strings like : 'template' and 'image'?

I read other posts but it was not clear to me.

like image 753
Delos Chang Avatar asked Dec 06 '25 20:12

Delos Chang


1 Answers

You could make a negating rewrite condition

Like this:

RewriteCond %{REQUEST_URI} !^/(template|image)
RewriteRule (.*) index.php/$1 [L]

Which effectively doesn't rewrite any urls pointing to things in the image and template folder.

  • Documentation on RewriteCond
  • Very good tutorial about htaccess and also goes deeply into url rewriting, worth the read
like image 148
sg3s Avatar answered Dec 08 '25 12:12

sg3s



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!