使htaccess规则仅适用于当前文件夹 [英] Make htaccess rule apply only to the current folder

查看:55
本文介绍了使htaccess规则仅适用于当前文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了如何将index.php更改为网址名称的示例

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]

.htaccess文件位于www.site.com/map/目录

所以它的作用是从www.site.com/map/index.php更改为www.site.com/map/country

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

它将index.php重写为url中的国家/地区名称,问题是当我访问一个目录或诸如www.site.com/map/countryname/state的子目录时,它只是replace the index.php inside the state directory to the index.php inside the map directory解决这个问题?或如何将其仅应用于当前目录?

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 ?

这是网站目录结构 http://ufile.io/3dii7 ,所以当我转到site/map/state/可以,但是我需要在url中输入国家名称,像​​这样site/map/country/state/

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/

推荐答案

将您的.htaccess设置为:

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]

这篇关于使htaccess规则仅适用于当前文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆