user7904096
user7904096

Reputation:

Make htaccess rule apply only to the current folder

I saw this example of how to change index.php to the 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 .htaccess file is inside the www.site.com/map/ directory

so what it does is change from www.site.com/map/index.php to www.site.com/map/country

it rewrite index.php to the country name in url, the problem is when I acess a directory above or sub directory like www.site.com/map/countryname/state it just replace theindex.phpinside the state directory to theindex.phpinside the map directory how to solve this ? or how to make this applied to the current directory only ?

Here is the site dir structure http://ufile.io/3dii7 so when I go to site/map/state/ it works but i need the country name in url to acess state dir like this site/map/country/state/

Upvotes: 2

Views: 1422

Answers (1)

anubhava
anubhava

Reputation: 785286

Have your .htaccess as this:

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]

Upvotes: 2

Related Questions