Angular HTML5模式,路由器在页面上重新加载状态

时间:2016-09-24 08:34:31

标签: php angularjs .htaccess

我正在尝试从我的网站中删除哈希标记。我通过以下代码实现了它。

$locationProvider.html5Mode(true);

同样在索引文件中添加了基本URL。

我的问题是,如果我在重新加载整个页面后处于contct-us状态。我正在重定向到本州,这被定义为其他州。

使用的配置是 -

服务器-Appache   数据库 - mysql

我在.htaccess中添加了以下代码,用于重写规则 -

     RewriteEngine On
     php_value post_max_size 120M 
    php_value upload_max_filesize 120M 
     php_value max_execution_time 90 



     RewriteCond %{HTTP_HOST} ^54\.201\.153\.244$ [NC,OR]

     RewriteCond %{HTTPS} off
     RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

      RewriteCond %{HTTP_HOST} ^adkarlo.com$ [NC]
        RewriteRule ^(.*)$ https://www.adkarlo.com/$1 [R=301,L]

      #RewriteBase /html/
      ErrorDocument 404 /404.php

    RewriteCond %{REQUEST_FILENAME} -f
     RewriteRule ^ - [L]
   RewriteRule ^(.*)$ index.php [L]

预期结果 - 从州联系我们重新加载任何我想要转到同一页面的页面。

1 个答案:

答案 0 :(得分:3)

为了支持重新加载HTML5模式路由URL,您需要实现服务器端URL重写,以将非文件请求(即,对于现有文件不明确的请求)定向到索引文件,通常是index.html

来自documentation

  

使用此模式需要在服务器端重写URL,基本上您必须重写所有指向应用程序入口点的链接(例如index.html)。

您的重写规则不应在目标网址中包含任何#。相反,请使用此

RewriteEngine on

# Don't rewrite files
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.php [L]

来源〜https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode

此外,无需设置RewriteBase