Reputation: 33
Situation
I am trying to implement named URL routing into my webapp based on the Fat Free Framework version 3.4.
The project I am working on is located in a subfolder, /foo So I access the project through localhost/foo
This works nicely, I can also access different URL routes without any issues.
Problem description
When I access a route in a template it gets rendered as <form method="POST" action="/do/stuff">
With the leading '/' the browser interprets it as the start of the webserver and therefore takes me to localhost/do/stuff instead of localhost/foo/do/stuff
Code
This is how I pass a named route into a template:
<form method="POST" action="{{ 'doStuff' | alias }}">
This is an example from my routes.ini
POST @doStuff: /do/stuff=Views->doStuff
.htaccess
RewriteEngine On
RewriteBase /foo/
RewriteRule ^(tmp)\/|\.ini$ - [R=404]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
apaches mod-rewrite is enabled. I feel like I have missed something important, but I have been trying for two days to get this to work, without luck. Any leads would be appreciated!
Upvotes: 3
Views: 1012
Reputation: 3908
The alias()
function returns a URL relative to the web app, not to the web root. Therefore, you should prefix it with the web app BASE
, like this:
<form method="POST" action="{{ $BASE }}{{ 'doStuff' | alias }}">
Upvotes: 2
Reputation: 4690
Add the following code to your <head>
<base href="{{ @SCHEME.'://'.@HOST.@BASE.'/' }}">
It sets the browser's default base and appends every url, even if it contains a /
to it.
Upvotes: 0