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

Che*_*tan 13 php .htaccess angularjs

我想从我的网站上删除哈希标记.我通过以下代码实现了它.

$locationProvider.html5Mode(true);
Run Code Online (Sandbox Code Playgroud)

以及索引文件中添加的基本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]
Run Code Online (Sandbox Code Playgroud)

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

Phi*_*hil 3

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

文档中

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

您的重写规则不应#在目标 URL 中包含任何内容。相反,使用这个

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]
Run Code Online (Sandbox Code Playgroud)

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

另外,无需设置RewriteBase