so I googled how to remove the hashtag from the url when using angularjs with laravel. Mainly all resources were as follows:
- Add
$locationProvider.html5Mode(true);to app.js - Update
base tagin layout page which isindex.php. Mine is as follows:<base href="/myproject/public/">
and it worked smoothly without any issues until I tried to refresh a page while working so I got the following:
NotFoundHttpException in RouteCollection.php line 161:
I checked for existing solutions which mainly state to create .htaccess in the root directory, add the following:
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html
but it still works the first time only and whenever I reload, nothing works.
Another answer stated to add the following to the routes file but when I tried it I got the following:
FatalErrorException in Facade.php line 216:
Call to undefined method Illuminate\Foundation\Application::missing()
UPDATE
I updated the .htaccess file as follows:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
<IfModule mod_proxy_http.c>
RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator [NC,OR]
RewriteCond %{QUERY_STRING} _escaped_fragment_
# Only proxy the request to Prerender if it's a request for HTML
RewriteRule ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent))(index\.php)?(.*) http://service.prerender.io/%{REQUEST_SCHEME}://%{HTTP_HOST}/$3 [P,L]
</IfModule>
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
</IfModule>
and on the server I updated /etc/apache2/sites-enabled/000-default.conf to be as follows:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/myproject/public
<Directory /var/www/myproject/public>
AllowOverride All
RewriteEngine On
RewriteBase /var/www/myproject/public
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ index.php [L]
</Directory>
</VirtualHost>
The hash is removed from the url but still whenever I refresh a page other than the home page, it gives 404 error. Any idea what's missing?!