3rd rule in .htaccess to redirect to specific file

Viewed 45

My code is following, the first 2 rules are working fine, but I'm unable to work the 3rd one(Check if its category eg. /some-folder) page should be served by category.php file. Can anyone help?

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

# WORKING - Check if its a product eg. /some-folder/some-product.html
RewriteRule ^/?([^/]+)/.+\.html$ product.php [QSA,L]

# WORKING - Check if its a page eg. /some-page.html
RewriteRule ^/?[^/]+\.html$ page.php [QSA,L]

# NOT WORKING - Check if its category eg. /some-folder
RewriteRule ^/?[^/]+\$ category.php [QSA,L]
1 Answers

With your shown samples, please try following edited htacess rules.

Please make sure to clear your browser cache before testing your URLs.

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
# WORKING - Check if its a product eg. /some-folder/some-product.html
RewriteRule ^([^/]*/)/([^.]*\.html)/?$ product.php [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
# WORKING - Check if its a page eg. /some-page.html
RewriteRule ^([^.]*)\.html/?$ page.php [QSA,NC,L]

# EDITED RULES here.. - Check if its category eg. /some-folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^/?[^/]+/?$ category.php [QSA,L]
Related