2016-09-24 136 views
13

我想從我的網站刪除哈希標記。我通過以下代碼實現了它。角HTML5模式,路由器去頁面重新加載

$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

不應該是路徑中的任何'#/' – charlietfl

+0

@charlietfl - 網址中沒有任何#/但有一次,我刷新頁面來自/ about。它將我重定向到/ home狀態,這是我在stateProvider中以其他方式給出的狀態。 – Chetan

+0

@charlietfl - 如果您向我推薦任何解決方案,我將非常感激。 :) – Chetan

回答

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

+0

我編輯了問題和代碼.htaccess文件中仍然有相同的問題。請幫助我 – Chetan

+0

@Chetan爲什麼你有'index.php?/'?它應該只是'index.php' – Phil

+0

嘗試與此以及..不工作:( – Chetan