Codeigniter add url suffix dynamically when search - php

In codeigniter website i have url like this www.mywebsitename.com/used-motorbikes, In that page there is form to search location when user select location EX: location1 then the url should change to something like this
www.mywebsitename.com/used-motorbikes-location1 is it possible to add like this?

Add logic in client side js to form this URL first. Then redirect window location to this.
In codeigniter make sure you have route added for www.mywebsitename.com/used-motorbikes-* and handle it to give needed response.
$route['used-motorbikes-(:any)']

Related

Laravel custom urls saved in database

I want to give custom urls to members of my site to have their pages under my site url like www.mysite.com/{theirurls}.
In database in user table i have a field userurl that keeps the url i give them.
In route i have written the code
Route::get('/{fpage?}', 'AController#fofpage');
In controller in fofpage function i take the variable and look for the value in database. If it belongs to someone redirects to this. If it isnt goes back to / (root).
The problem is that all the other urls like login and others doesnt work.
How can i solve this problem?
Thanks in advance
Put this route at the end of the web routes file to make it work:
Route::get('/{fpage?}', 'AController#fofpage');
You'll also want to validate user URLs and not allow users to enter values like login, register etc.

PHP Rewrite URL or Mask or Redirect?

I'm trying to get domain.com/employee?display_county=sd&dept=sales&id=23 to display in the URL as domain.com/firstnamelastname while retaining the URL variables.
And also if someone goes directly to domain.com/firstnamelastname it would still have the original URL variables.
How would one accomplish this?
Edit: OK, so I'm starting to rethink this...
Let's say I have a page that displays a list of users.
Each user has a clickable link that directs to domain.com/employee?display_county=XX&dept=XXXXX&id=XX
How could I get the URL to display domain.com/firstnamelastname when a user is clicked and still bring up the correct user?
I was thinking maybe using a POST method to pass the id to the script that displays the user and then rewriting the URL to display the firstnamelastname related to the id, but then browsing directly to domain.com/firstnamelastname would leave the id variable empty...

Redirect to full url, using id

I am working on a webapp. There are items accessible the way using item id in the url web.site/123, where 123 is item id. I want to redirect visitors to the full url page like web.site/123-the-item, and I also want to use full links within my website.
Any good idea how to do it?
I don't need the code, I am looking for a simple yet nice and effective idea. The title is obviously in the database, so there will be one select needed anyhow. But I am not sure, if I should redirect once and every single time visitor visits the site without checking if the url is full (doesn't seem nice) or should I check the url and redirect only if it doesn't match the title?
I am using nginx, php, mysql and laravel 5.2 in case there is a workaround for this scenario I am not aware of.
Try adding route like
Route::get('/{id}',['uses' => 'ContentController#byId'],'where'=>['id'=>'\d*']);
And in that action you can check in database if id exists and redirect user to proper url
You can check use regular expressions to check the if the incoming request has just the id and have them mapped to particular routes. In the digit route you can redirect.
E.g.
your route file should be something like this :
Route::get('item/{id}', function ($id) {
//redirect to the full name route
})
->where('id', '[0-9]+');
Route::get('item', 'SomeController#somemethod');
Read more here.

UrlManager hide id - Yii2 [duplicate]

'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>'
I have written this rule in url manager so that it hide id during update action i want the url should be / the id should be hidden. But no luck.
eg:
I have this url mysite.com/controller/update/1 i want the url to be mysite.com/controller/update
What you are trying to achieve is impossible and useless.
Think about it logically. Action in this case simply won't know exactly what model should be loaded and updated.
I see only one possible use case of that.
When you load page post/update, then select post from list to update and load it with AJAX.
In this case just remove id from action parameters, you don't need to write additional url rules for that.

GET form restructure url

i have a form using the GET method and i'm currently redirected to this url
www.mysite.com/index.php?token=123&cl=page&searchparam=mysearchtext
And i want to trick the get method via htaccess to rewrite the url to this
www.mysite.com/index.php?token=123&cl=page&searchparam=anothertext
How can i do it without the header(location).

Categories