Vercel: How to rewrite vercel urls correctly? - url-rewriting

Maybe I don't quite understand what rewriting means, or I'm not doing it right, but I'll put you in the context of what I want to happen and it's not happening, if someone can help me.
I have a project created which had its vercel domain as "example.vercel.app" but I put mine and now it has its custom domain as "example.com".
So far everything normal.
But now I have the problem that within my structure I have index.html in the root folder, that his url is translated as "https://example.com" and in another root folder called html I have the file contact.html that if I go to it from another file I would have the url as "https://example.com/html/contact", but instead I want it to stay as "https://example.com/contact", I don't know how I can get this, if someone could help me.
In my vercel.json file I have this configuration:
{
"cleanUrls": true,
"rewrites": [
{
"source": "/html/contact",
"destination": "/contact"
}
]
}
And from my html file I go to the route like this:
Contact
I make the call to the route like this to be able to redirect myself in production of course.
Also, in case it was the problem, I have already tried directing myself to the route in my html like this:
Contact
But it does not work.
So I no longer know how I should do to achieve my goal, if someone knows how to help me I would greatly appreciate it.

Related

Laravel forcing Http for asssets

this is a little bit strange because most of the questions here wanted to force https.
While learning AWS elastic beanstalk. I am hosting a laravel site there. Everything is fine, except that none of my javascripts and css files are being loaded.
If have referenced them in the blade view as :
<script src="{{asset('assets/backend/plugins/jquery/jquery.min.js')}}"></script>
First thing I tried was looking into the file/folder permissions in the root of my project by SSHing into EC2 instance. Didn't work even when I set the permission to public folder to 777.
Later I found out that, the site's main page url was http while all the assets url were 'https'.
I dont want to get into the SSL certificates things just yet, if it is possible.
Is there anyway I can have my assets url be forced to Http only?
Please forgive my naiveity. Any help would be appreciated.
This usually happens if your site is for example behind an reverse proxy, As the URL helper facade, trusts on your local instance that is beyond the proxy, and might not use SSL. Which can be misleading/wrong.
Which is probaly the case on a EC2 instance... as the SSL termination is beyond load balancers/HA Proxies.
i usually add the following to my AppServiceProvider.php
public function boot()
{
if (Str::startsWith(config('app.url'), 'https')) {
\URL::forceScheme('https');
} else {
\URL::forceScheme('http');
}
}
Of course this needs to ensure you've set app.url / APP_URL, if you are not using that, you can just get rid of the if statement. But is a little less elegant, and disallows you to develop on non https

laravel in subdirectory but route points to parent directory

i have a problem in laravel route i don't know how to fix it!
well first of all i should say my webserver is lighttpd and there's no way to change it to nginx or apache if you want to say use another webserver... :D
well, my project was in "/path/to/some-where/htdocs" and my domain was "example.com"
and in "lighttpd.conf" i pointed "example.com" to "/path/to/some-where/htdocs/public/" and everything worked well and laravel worked fine, but because of some reasons i made some changes cause we needed "example.com" domain for some other projects
i moved project to "foo" subdirectory so now my project path is "/path/to/some-where/htdocs/foo/" and also i made some changes in lighttpd and pointed "example.com/foo" to "/path/to/some-where/htdocs/foo/public/"
also i changed APP_URI in .env to "http://example.com/foo"
but when i open "example.com/foo" it shows me "route not found" error, laravel it's working but it doesn't recognize "/foo" as base directory and when i put all of routes in a route group with "foo" prefix it works fine!
for testing i made these routes
Route::get("/", function(}{return "sweet home!";));
Route::get("/{slug}", function($slug}{return $slug;));
when i open "example.com/foo" it should show me "sweet home" but instead, it shows me "foo" cause as i said laravel doesn't recognize "foo" as base directory
it seems i should change base directory or base uri of project but i couldn't find anything
as i said i changed APP_URI, and also i put
RewriteBase /foo/
in .htacess but no result!
You should prefix your routes this way :
Route::group(['prefix' => 'foo'], function() {
Route::get("/", function(}{return "sweet home!";));
Route::get("/{slug}", function($slug}{return $slug;));
});

Web Api Help Page route

I was recently tasked with fixing one of our Help Pages that had gone down. I hadn't ever worked on one before, so I jumped in and started playing around with it. I noticed we had this route set up for the Help Page:
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"HelpPage_Default",
"api/v1/Help/{action}/{apiId}",
new { controller = "Help", action = "Index", apiId = UrlParameter.Optional });
HelpPageConfig.Register(GlobalConfiguration.Configuration);
}
I compared it to another working Help Page route and found the url to be different. I changed the url to
"Help/{action}/{apiId}"
and it worked. I've done some research online (this helped) but still fail to understand why changing the url would make any difference on whether that page would be hit. It would make sense to me that if I went to mydomain.com/api/v1/Help that I would still hit the help page with the original url.
Thank you in advance.
Route what you have "api/v1/Help/{action}/{apiId}" this is wrong because format of the route should be [Controller]/[Action]/[Id] and your controller is Help not "api/v1" .
And to answer your question to "mydomain.com/api/v1/Help" this url hitting the help page, yes it will if you give "help/{action}/apidid" url in the route.
"api/v1" till here its your IIS virtual directory setup not a route in your application configuration.

Laravel 5 Route Strange Behaviour

I have a Laravel site set up on a Homestead box, so I'm accessing it on sitename.app:8000. I have a route called "news" but when I try to go to sitename.app:8000/news I get oddly bounced out to sitename.app/news/.
If I change the routename to "news2" I can access the desired controller action as per normal at sitename.app:8000/news2. So somehow it's "news" itself that has become uncooperative - and I'm pretty sure that we aren't even getting as far as the NewsController, when I try to access that url.
Can anyone work out from these symptoms what might be going wrong? One "news"-related change I made at some point was to add $router->model('news', "App\News"); in the boot method of the RouteServiceProvider, but removing this doesn't seem to make the difference.
ETA: People keep asking for the routes.php file. I can literally remove everything from the file except
Route::get('news', function() {
return "hello world";
});
Route::get('news2', function() {
return "hello world";
});
and /news2 will work but /news will bounce me out. So I remain pretty convinced that the problem is somewhere deeper than routes.php...
I finally worked out what boneheaded action of mine had been causing this behaviour!
I had created a folder in /public named "news"... i.e. with the same name as an important route. Not sure exactly what havoc this was wreaking behind the scenes for Laravel every time a request for /news was being made, but one can assume it was nothing good.
Advice for anyone tearing their hair out over a route that "mysteriously doesn't work" - check your public folder for possible collisions!
This is a known issue Larvel missing port
The easiest way to solve this problem is to go to public/index.php and set the SERVER_PORT value.
$_SERVER['SERVER_PORT'] = 8000;
Don't forget to set the base url in the config if you are using links on website, the url generator uses the base-url defined in the config.
Last option is to change the vm portfoward in VagrantFile to point to port 80 and use port 80 for your app.

Tincr for ASP.NET MVC 3

I am trying to use the tincr extension in chrome. It allows you to refresh css and javascript without having to reload the page again. I'm having some trouble getting it working and would appreciate any help.
My Setup
Source code root directory:
C:\dev\tfs\MyApp\Development Branches\3.3.0.0\Presentation\MyApp
IIS website directory points to the root directory above. The Scripts directory underneath the folder path above contains the js files that I am changing.
I created a tincr.json file and put it in the root directory
tincr.json
{
"toFile" : [],
"fromFile" : [
{"from": "C:\\\\dev\\\\tfs\\\\MyApp\\\\Development Branches\\\\3.3.0.0\\\\Presentation\\\\MyApp\\\\Scripts\\\\(.+\\.js)",
"to": "http://localhost/MyApp/Scripts/$1"}
]
}
Is this correct? Has anyone managed to get tincr working with ASP.NET MVC 3? Thank you for your help.
PS - I don't have the rep to create a tincr tag so if someone could add that to this it would make it easier for others to post questions about it too. Thanks.
After playing around and reading google groups and other web sites I pieced together the following
Tincr does not work with query parameters in windows (eg. common.js?var=1 will fail)
You need to be careful of ajax queries that append to the url for js files that come from references to ajax code. Use Fiddler and watch the URLS. I had to make sure that the js file was added to the _Layout.cshtml file and then it would come out without query parameters.
I put a more detailed how to for Tincr on my website http://aboutdev.wordpress.com/2013/01/26/using-tincr-with-asp-net-mvc-in-windows-7/ but here is what you need.
The tincr.js file I used looks as follows:
{
"toFile" : [],
"fromFile" :
[
{
"from": "\\\\Scripts\\\\([a-zA-Z]+)\\.js",
"to": "/MyApp/Scripts/$1.js"
}
]
}
This file does not update the file on disk because 'tofile' is not filled in.
This file will look for files in the Scripts directory that is directly under the root where you put your tincr.json file.
I hope this helps you with using Tincr in your pojects.

Resources