user2039290
user2039290

Reputation: 104

htaccess doesn't work as I expected

I have the following script:

Options +FollowSymLinks
RewriteEngine On

# PATH
RewriteBase /bbv/

# ERROR RULE
ErrorDocument 404 /bbv/404.php

# WORKS
RewriteRule ^home$ index.php
RewriteRule ^contact$ contact.php
RewriteRule ^(.*)\.html$ template_cat.php?cat=$1 [L]

# THIS DOES NOT WORK
RewriteRule ^(.*)\(.*)-(.*)$ template_prod.php?cat=$1&prod=$2&id=$3 [L] 
RewriteRule ^(.*)$ template_cat.php?cat=$1 [L]

And I want to be like: localhost/bbv/category and localhost/bbv/category/product-id

Where is the mistake? tx.

Upvotes: 2

Views: 49

Answers (1)

anubhava
anubhava

Reputation: 784908

Use this code:

# ERROR RULE
ErrorDocument 404 /bbv/404.php    
Options +FollowSymLinks
RewriteEngine On    
# PATH
RewriteBase /bbv/

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

# WORKS
RewriteRule ^home$ index.php [L]
RewriteRule ^contact$ contact.php [L]
RewriteRule ^([^.]+)\.html$ template_cat.php?cat=$1 [L,QSA]

RewriteRule ^([^/]+)/([^-]+)-(.+)$ template_prod.php?cat=$1&prod=$2&id=$3 [L,QSA] 
RewriteRule ^(.+)$ template_cat.php?cat=$1 [L,QSA]

Upvotes: 2

Related Questions