Make htaccess rule only apply to current folder

I saw this example of how to change index.php to url name

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^([a-z0-9-_.]+)/?$ index.php?id=$1 [NC,L]
RewriteRule ^([a-z0-9-_.]+)/([a-z0-9]+)/?$ index.php?id=$1&goto=$2 [NC,L]

      

This file .htaccess

is inside the directorywww.site.com/map/

what he does is change from www.site.com/map/index.php

towww.site.com/map/country

it rewrites index.php to the country name in the url, the problem is when i get the directory above or subdirectory for example www.site.com/map/countryname/state

it just replace the

index.php inside the state directory to the

index.php inside the map directory

how to solve this? or how to make it only applicable to the current directory?

Here is the dir structure of the site http://ufile.io/3dii7 , so when I go to site/map/state/

it works, but I need the country name in the url to access this typesite/map/country/state/

+3


source to share


1 answer


You have .htaccess:



RewriteEngine On

# skip all rules below this for files and directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^([\w-.]+)/?$ index.php?id=$1 [L,QSA]

RewriteCond %{DOCUMENT_ROOT}/site/map/$2 -f
RewriteRule ^([\w-]+)/(.+)/?$ $2?id=$1&goto=$2 [L,QSA]

RewriteCond %{DOCUMENT_ROOT}/site/map/$2/index.php -f
RewriteRule ^([\w-.]+)/([a-z0-9]+)/?$ $2/index.php?id=$1&goto=$2 [NC,L,QSA]

RewriteRule ^([\w-.]+)/([a-z0-9]+)/?$ index.php?id=$1&goto=$2 [NC,L,QSA]

      

+3


source







All Articles