RewriteCond 排除目录及其子目录

发布于 2024-10-01 14:03:31 字数 885 浏览 0 评论 0原文

我一直在尝试让维基百科风格的语言发挥作用。这样,英语的网址将是 en.example.com,法语的网址是 fr.example.com,等等...这工作正常,但我希望管理员区域始终默认为基本语言,即不设置 LANGUAGE 环境变量。我尝试添加 RewriteCond %{REQUEST_URI} !^admin [NC] 但似乎没有效果。

我的 mod_rewrite 代码如下:

# Handle languages 
# Picks up the language code from the browser accept-language parameter
RewriteCond %{HTTP:Accept-Language} ^([a-z]{2}).*$ [NC]
RewriteCond %{HTTP_HOST} !^[a-z]{2}\.[a-z]{2,}\. [NC]
RewriteRule ^(.*)$ http://%1.%{HTTP_HOST}/$1 [R=301] 

RewriteCond %{REQUEST_URI} !^admin [NC]
RewriteCond %{HTTP_HOST} ^([a-z]{2})\.[a-z]{2,}\. [NC]
RewriteRule ^(.*)$ - [ENV=LANGUAGE:%1,QSA]

# Redirecting all requests to one script
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([\+a-zA-Z0-9,%\(\)\_\ -/]+)$ /index.php [NC,L,QSA]

感谢您的帮助,我确信这是一个非常愚蠢的错误,像往常一样。

I've been trying to get a wikipedia style language thing to work. So that the url will be en.example.com for English, fr.example.com for French, etc... This is working fine however I would like the admin area to always default to base language, i.e. not set the LANGUAGE environment variable. I've tried adding RewriteCond %{REQUEST_URI} !^admin [NC] but it seems to have no effect.

My mod_rewrite code is as follows:

# Handle languages 
# Picks up the language code from the browser accept-language parameter
RewriteCond %{HTTP:Accept-Language} ^([a-z]{2}).*$ [NC]
RewriteCond %{HTTP_HOST} !^[a-z]{2}\.[a-z]{2,}\. [NC]
RewriteRule ^(.*)$ http://%1.%{HTTP_HOST}/$1 [R=301] 

RewriteCond %{REQUEST_URI} !^admin [NC]
RewriteCond %{HTTP_HOST} ^([a-z]{2})\.[a-z]{2,}\. [NC]
RewriteRule ^(.*)$ - [ENV=LANGUAGE:%1,QSA]

# Redirecting all requests to one script
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([\+a-zA-Z0-9,%\(\)\_\ -/]+)$ /index.php [NC,L,QSA]

Thanks for any help, I'm sure it's something really stupid that is wrong, as usual.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吐个泡泡 2024-10-08 14:03:31

你的问题是 REQUEST_URI 不以 admin 开头,它前面会有一个斜杠...如果你没有重写基础,它可能以 /admin 开头...所以你可以将其更改为 !^/admin 或只是!admin 或 !admin/ 如果您的所有代码都在 foo.com/admin/*

REQUEST_URI 将是整个 GET,如“/foo/bar.html”

Your problem is that REQUEST_URI doesn't start with admin, its going to have a slash in front... it might start with /admin if you have no rewrite base... so you can change it to !^/admin or just !admin or !admin/ if all your code is in foo.com/admin/*

REQUEST_URI is going to be the entire GET like "/foo/bar.html"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文