Laravel subdomain route problame - laravel

I am working on a subdomain system on laravel.
suppose my main domain name is: test.test
and my subdomain name is: subdomain.test.test
Now, the problem is, when I use the main domain route in sub-domain blade file like:
Profile
then, it should generate links like test.test/profile
but, it's generating links with subdomain like: subdomain.test.test/profile
Now, How can I solve this problame?

An alternative would be to use relative path instead of absolute using route() helper third parameter.
Profile

I recommend you to use Spatie Multitenancy, when i do route('home'), he return back the url with the actual domain.

Related

Passing more than one parameters in route messes up my view

I am a beginner to laravel. When I pass more than one parameter through the route my view gets messed up. For example when my route is {{URL/product}}. It is ok, but when try it the other way i.e {{URL/product/anything}}, the view is messed up.
[This is the correct view][1]
These are my routes :
(Working)
Route::get('/addproduct' , 'AdminController#add_product')->name('add_product');1
(not working)
Route::get('/add/product' , 'AdminController#add_product')->name('add_product');This one is not working
I haven't changed anything but my web.php file.
This is probably because of how you are linking to your assets. You are most likely using relative URLs. Try using one of the URL helpers to generate absolute URLs for you.
href="{{ asset('css/somefile.css') }}"
Laravel 7.x Docs - Helpers - URLs asset

Generate route url from subdomain to the main domain

I have a multi-tenant app. So let's say I have test.app.com and app.com. I can successfully navigate from app.com to test.app.com but I am unable to the opposite.
I tried wrapping the routes of my app.com inside a Route::domain() but that only gives me a 404 error instead of actually redirecting it to the url
EDIT: Just to make sure, I want to redirect using a relative path (with the route() method).

Laravel project custom domain

I am using custom configuration of domain names for my laravel project test as test.local . When I ran this project as test.local in google chrome , it shows laravel homepage. But, when I go to any other routes it shows internal server error.
Can anyone have any solution?
Just add index.php after the url, and then go to specific route
test.local/index.php/login
So in your routes file eg. web.php, do this if you need to, this adds on a domain limitation.
Route::group(['domain' => env('APP_URL', 'test.local')],function () {
//routes...
});
In you .env file, define the app url, you may use https if required
APP_URL=http://local.test
After all, I would strongly suggest you to check you nginx file to see if you are pointing the path to the right one. And also check if index.php is added into the index file property.

How to load an codeigniter application by using different url

Now I am developing an application by using CodeIgniter framework. In this application, there is a section which name account setup. By using this section we can create multiple accounts. As an example, accounts name are abc, bca or anything. And Suppose my site URL is: www.xyz.com (base_url) Then we need to access the site by the domain name and also domain name with account name like bellow:
www.xyz.com
www.xyz.com/abc/
www.xyz.com/bca/
www.xyz.com/anything/
For More clear, URL pattern will be:
www.xyz.com/dashboard/index
www.xyz.com/abc/dashboard/index
www.xyz.com/bca/dashboard/index
How can we do it? I need your suggestion.
Yes it's Possible through codeigniter Routs.
Go to application\config Open a file which Name is routes.php
you can call the controller functions see in code example
example
$route['new_project'] = "controller/function";
when you hit your website url like this www.xyz.com/new_project it will go to your mention controller and function.
see the documentation of routs CodeIgniter URI Routing
example 2:
$route['account/(.*)'] = "controller/function";
Now we you redirect your url like this
redirect('account/'.$name_var.'');
Now your url look like this.
www.xyz.com/account/name_of_logged_in_user
Also you can use this like this.
$route['(.*)/dashboard/index'] = "controller/function";
And then you can call it like this.
redirect(''.$name_var.'/dashboard/index');
And from this code your output url show something like this.
www.xyz.com/name_of_logged_in_user/dashboard/index
Hope it will help you if any question add comment
There are many way to do it.
1) Domain alias if you want to run same script with different domain.
2) if you want to run same script with sub domain then you can do it from Cpanel
3) If you want to run same script with different folders in same domain then you need to use htaccess

Encrypt URL with PHP Codeigniter

I have developed a website with PHP Codeigniter. It consists of many controllers and views. I want to encrypt the URL of the site to hide the controller and function name. Currently, the URL looks like this :
www.sitename.com/controller_name/function_name
I don't want the users to see the controller and function names. Is it possible to do this now because the site is almost complete. Is there any shortcut of doing this? Please Help
You can use codeigniter URI Routing to remove your controller name from URL.
$route['url_name'] = 'controller_name/function_name';
This `www.sitename.com/url_name` will look go to `www.sitename.com/controller_name/function_name`
$route['url_name/(:any)'] = 'controller_name/$1';
This will only change your controller name.. `controller_name` to `url_name`

Resources