TypeError : Cannot read property 'replace' of undefined

会有一股神秘感。 提交于 2019-12-13 02:25:28

问题


Overview :

I would like to redirect the visitor on a default page(index.html) inside the directory structure to display when a directory is accessed using .htaccess file(as of now current directory index.html is loading).

But When I turn on $locationProvider.html5Mode(true) in my angular application getting below error.

Console Error :

Directory structure of Application :

public_html
  --prod
    --public
      --app
        --controllers
        --directives
        --services
        --app.config.js
    --index.html
  --.htaccess
.htaccess

public_html => .htaccess :

DirectoryIndex prod/public/index.html

This .htaccess is used to redirect the visitors on a application page (prod/public/index.html) directly by using domain name, as of now when user visit the domain the current directory(public_html) index.html is loading.

public_html => prod => .htaccess :

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /prod/public/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*) /prod/public/#/$1 
    RewriteCond %{HTTP_HOST} ^example.com [NC]
    RewriteRule ^(.*)$ http://www.example.com/prod/$1 [L,R=301]
</IfModule>

prod => public => index.html :

<base href="/prod/public/">

Everything working fine If i removed $locationProvider.html5Mode(true) from my app.config.js file.So, when I comment out the $locationProvider code, everything works fine in # mode. I can get to /#/abc, etc. without issue. As soon as I put the $locationProvider parts back in, nothing happen.

Related issues on Stack Overflow with no success :

$locationProvider.html5Mode(true) issues

Angular html5 mode not working in apache


回答1:


Inside public_html => .htaccess have this rule instead:

DirectoryIndex index.html
RewriteEngine On

RewriteRule ^/?$ prod/public/index.html [L]

then public_html => prod => .htaccess should have this:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ public/index.html [L]


来源:https://stackoverflow.com/questions/39026692/typeerror-cannot-read-property-replace-of-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!