Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess file with some exceptions

I need a .htaccess file that follows these rules:

  • all files (and subfolders/subfiles) of the folders images, css, js, admin, fonts should be reachable
  • urls like bla.com/info should be redirected to bla.com/index.php?p=info
  • urls like bla.com/products/22 should be redirected to bla.com/index.php?p=products&cat=22
  • the url bla.com/products should be redirected to bla.com/index.php?p=products

Can anyone help me with this? This is what I got so far:

Options +FollowSymLinks

RewriteEngine On
RewriteBase /staging/

RewriteRule     ^favicon.ico           favicon.ico         [NC,L]
RewriteRule     ^([A-Za-z0-9-]+)/?$     index.php?p=$1       [NC,L] 

But it only works for the first 2 conditions...

Thanks!!

like image 492
gait Avatar asked Aug 05 '26 10:08

gait


1 Answers

These 2 rules should work for you:

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^([a-z0-9-]+)/?$ index.php?p=$1 [NC,QSA,L]

RewriteRule ^([a-z0-9-]+)/([a-z0-9-]+)/?$ index.php?p=$1&cat=$2 [NC,QSA,L]
like image 124
anubhava Avatar answered Aug 07 '26 01:08

anubhava



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!