我正在尝试重定向到 www.domain.com/store/bg/user/login
每当有人尝试 www.domain.com/STOREADMIN/bg/user/login
(大写只是为了强调)。 url 的语言部分可以是另一种语言 ( .../../en/../..
)。
这是全部.htaccess
文件:
Options -Indexes
# follow symbolic links
Options FollowSymlinks
RewriteEngine on
#RewriteRule ^(store)($|/) - [L]
#RewriteRule ^/store/(.+) http://store.tashev.bg/$1 [R,L]
RewriteCond %{REQUEST_URI} ^/storeadmin/[a-z]{2}/user/login
RewriteRule ^/storeadmin/([a-z]{2}) %{HTTP_HOST}/store/$1/user/login [R=301,L]
RewriteCond %{REQUEST_URI} ^/admin/$
RewriteRule ^(admin)/$ /$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule ^admin(/.+)?$ /backend/web/$1 [L,PT]
RewriteCond %{REQUEST_URI} ^.*$
RewriteRule ^(.*)$ /frontend/web/$1
这是我添加的部分:
RewriteCond %{REQUEST_URI} ^/storeadmin/[a-z]{2}/user/login
RewriteRule ^/storeadmin/([a-z]{2}) %{HTTP_HOST}/store/$1/user/login [R=301,L]
它有什么问题吗?我也试过没有 %{HTTP_HOST}
.
提前致谢!
最佳答案
使用这个:
# you were missing a '+' here
Options +FollowSymlinks
RewriteEngine on
AddDefaultCharset UTF-8
# use %1 to target the stored expressions with () from the RewriteCond
# use $1 to target the stored expressions with () from the RewriteRule
# the ? means that the preceeding character may or may not exist
# NC flag means the RewriteRule to be matched in a case-insensitive manner.
RewriteCond %{REQUEST_URI} ^/?storeadmin/([a-z]{2})/user/login/?$ [NC]
RewriteRule ^(.*)$ /store/%1/user/login [NC,R=301,L]
关于.htaccess - Htaccess 重写并重定向到 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48461331/