.htaccess - Htaccess 重写并重定向到 url

标签 .htaccess redirect mod-rewrite

我正在尝试重定向到 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/

相关文章:

apache - Apache 的 Header 配置中的 "always"和 "onsuccess"有什么区别?

php - 在服务器上找不到 Silex 'App\Controller\IndexController'

linux - mod_rewrite 不适用于子域

.htaccess - HTACCESS 重写的 URL 正在重定向查询参数

apache - 当 Apache 将 HttpS 请求重定向到 http 时,Chrome 抛出 ERR_CONNECTION_REFUSED

apache - Rewritecond - 错误的标志分隔符 .htaccess (Apache)

php - 如何从 URL 中删除这种类型的字符串 #VTkfzCGqqkow

asp.net - 如何将 404(错误 url)重定向到主页

php - 错误的重定向 CakePHP

redirect - 如何在AngularJS中的http.get中进行重定向?