how to pass subfolder params in htaccess

Viewed 55

I am trying to pass the parameters of a subfolder of a url but I have not been successful. I only get the parameter from url 1 but when trying to get the parameter in url 2 it throws me access forbidden error

url 1 - web.com/folder/param1

url 2 - web.com/folder/subfolder/param1

RewriteEngine on
RewriteBase /folder

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

RewriteRule ^([^/]*)/?$ index.php?param1=$1 [L,QSA]
1 Answers

With your shown samples, please try following htaccess rules. Please make sure your htaccess is placed along side with folder folder(not inside it).

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

RewriteEngine on
RewriteBase /folder/

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

##2 parameter handling rules here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/(.*)/?$ index.php?param1=$1&param2=$2 [L,QSA]

##1 parameter handling rules here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?$ index.php?param1=$1 [L,QSA]
Related