htaccess 的 RewriteRule 隐藏默认语言
在 Zend 配置默认值中,我有以下规则:
SetEnv APPLICATION_ENV offline
RewriteEngine On
Options +FollowSymlinks
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
当我尝试添加下面的行时,不会发生:
RewriteRule ^en/(.*) $1 [L]
结果我期望永久重写 http://example.com/en/something 到 http://example.com/something 现在我的两个链接都是分开工作的。
编辑:
SetEnv APPLICATION_ENV offline
RewriteEngine On
Options +FollowSymlinks
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI} !^/en/
RewriteRule ^.*$ index.php [NC,L]
RewriteRule ^en/(.*) /$1 [L,R]
这会将默认语言 URL 直接重定向到站点根目录! 非常感谢。
LigHTTPD 有:
$HTTP["url"] != "^/en/" {
url.rewrite-once = (
"^/.*" => "index.php?/$1",
)
}
url.redirect = (
"^/en/.*" => "/$1",
)
In Zend configuration defaults I have these rules:
SetEnv APPLICATION_ENV offline
RewriteEngine On
Options +FollowSymlinks
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
When i try to add fallowing line, notfing happens:
RewriteRule ^en/(.*) $1 [L]
On result I expact to rewrite permomently http://example.com/en/something to http://example.com/something
At now I have both links worked separatly.
Edited:
SetEnv APPLICATION_ENV offline
RewriteEngine On
Options +FollowSymlinks
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI} !^/en/
RewriteRule ^.*$ index.php [NC,L]
RewriteRule ^en/(.*) /$1 [L,R]
This will redirects default language urls directly to site root!
Many thanks.
There is for LigHTTPD:
$HTTP["url"] != "^/en/" {
url.rewrite-once = (
"^/.*" => "index.php?/$1",
)
}
url.redirect = (
"^/en/.*" => "/$1",
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为
RewriteRule ^.*$ index.php [NC,L]
正在重写它,并且它永远不会达到您添加的规则。您需要添加一个条件,以便以/en/
开头的请求不会被重写到index.php:编辑:
example.com/en/something
被重定向到example.com/something
,然后重写为index.php
。It's bceause
RewriteRule ^.*$ index.php [NC,L]
is rewriting it and it never gets to the rule you added. You need to add a condition so that requests starting with/en/
don't get rewritten to index.php:Edited:
example.com/en/something
gets redirected toexample.com/something
, then rewritten toindex.php
.