从angularjs+;中的.htaccess获取参数;用户界面路由器
我的应用程序是一个多语言(从angularjs+;中的.htaccess获取参数;用户界面路由器,angularjs,.htaccess,angular-ui-router,Angularjs,.htaccess,Angular Ui Router,我的应用程序是一个多语言(angular translate)angularjs应用程序,带有ui路由器。从.htaccess重定向获取参数时遇到问题 我想要的是下面的路由。 www.example.com/en=英文版 www.example.com/he=希伯来文版本 www.example.com/ar=阿拉伯语版本 其他任何内容都已重定向到英文版本 在客户端 我的app.config如下所示: 语言状态 现在转到服务器端。 我添加了一个.htaccess文件,其中包含以下内容: &l
angular translate
)angularjs
应用程序,带有ui路由器
。从.htaccess
重定向获取参数时遇到问题
我想要的是下面的路由。
=英文版www.example.com/en
=希伯来文版本www.example.com/he
=阿拉伯语版本www.example.com/ar
- 其他任何内容都已重定向到英文版本
app.config
如下所示:
语言状态
现在转到服务器端。
我添加了一个.htaccess
文件,其中包含以下内容:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /7for70/index.html [L]
</IfModule>
重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$/7for70/index.html[L]
问题是,如果我尝试导航到www.example.com/ar
,它只会重定向到www.example.com/en/
和$stateParams.lang==='en'
如何将url的结尾转发到ui路由器。对于任何最终遇到相同问题的人,在两天的撕扯后,我有了一个想法 我在url后面加了一个斜杠,如下所示:
www.example.com/en=>www.example.com/en/
www.example.com/he=>www.example.com/he/
www.example.com/ar=>www.example.com/ar/
编辑:(约20分钟后) 似乎您需要在抽象状态中添加一个尾随斜杠,然后将其从其余状态中删除 因此,抽象状态是:
url:'/:lang/'
然后主状态将是
url:“
@Edison有趣的文章,但不能解决我的问题。在我的语言状态下,我专门在url路径中定义参数。
$stateProvider.state('app.home', {
url: '/',
template: '<sh-main/>'
});
$locationProvider.html5Mode(true);
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /7for70/index.html [L]
</IfModule>
$urlRouterProvider.rule(function ($injector, $location) {
var path = $location.url();
// check to see if the path already has a slash where it should be
if (path[path.length - 1] === '/' || path.indexOf('/?') > -1) {
return;
}
if (path.indexOf('?') > -1) {
return path.replace('?', '/?');
}
return path + '/';
});