Create an SEO friendly url in Codeigniter - codeigniter

I have a scenario to create an SEO friendly URL in Code-igniter.
http://example.com/en/motors/used-car-for-sale/audi?sub_categories3=36
I want to create an SEO friendly url and remove the portion ?sub_categories3=36 from the url. The subcategory id 36 will be the 'A4'(Audi A4 car model).
So the url should be http://example.com/en/motors/used-car-for-sale/audi/a4 .
The sub_categories3 will be the id of each type under main category.
How can i do it?I found lot of articles to it.Please suggest me a best way to find it.

Pass all /motors requests to the correct controller with ('motors/(:any)') = 'myController/myFunction';
Get the second part of the url and pass it to a model that requests an article with that URL. Use the 'URL' helper for this.
Return data back to the controller and to your view.

Related

What is the best practice to handle friendly urls in Laravel?

We have an online-shop.
We can have any friendly urls
as for separate models like products or categories (/iphone-6-white = /iphones/23)
as for custom filter urls like (/cool-flashes = /flash?cap=32gb&col=white)
What is the best practice to handle all urls?
IMHO we should create a table where we should store two cols (urlFrom and RedirectUrl). But redirect is not good way for us because we do not want a redirect, we just want to show appropriate content under the urlFrom.
I want to store it in a single table to make just one request to DB to find out whether we have the url or not.
You can create submit your form in array such as search[name], search[price][form] and create your custom Middleware that will checks request contain of search[] build url and after that redirect to this page.
Of course after that you must create route for those page, like:
Route::get('/search/{searchName?}/{searchPriceFrom?}', 'ProductsController#search');
Where your RoutesServiceProvoider will look like this:
Route::bind('searchName', function($term) {
// your DB query and checks...
});

How to call a customly created url in magento

I have added one field in backend for adding url for Faq Post and successfully saved to the database.But I`m not sure how to call it back the url to display that particular post.My requirement is to generate a url for each faq categories post and have separate link to access them.
For example .If my faq category is Test and particular post in that category is test123.I want to generate link to access test123 something similar to {mywebsite}/faq/{faq_category}/{faq_post}.Please help me.
You need to Use "Url rewrite Management" when you save url in magento then also save url in url rewrite.
You need to save in url table following fields:
id_path = "faq/{faq_category_id}/{faq_post_id}"
request path ="faq/{faq_category}/{faq_post}"
target path = "faq/index/view/cat/{faq_category_id}/post/{faq_post_id}"
you need to create controller View action in indexController of your module.
you can get parameter like this :
$category_id = $this->getRequest()->getParam('cat');
$post_id = $this->getRequest()->getParam('post');
now run url {mywebsite}/faq/{faq_category}/{faq_post}

How to map multiple URLs references of same content to one SEO friendly URL?

In My Application
We can access user profile screen by any of next URLs format
http://example.com/users/123/
http://example.com/users/123/mike
http://example.com/users/123/mike-pedro
But the problem is that
Now many URLs will show the same content
Because i dont care about last {slug}, i only use {id} to show the content
And according to
http://blog.codinghorror.com/url-rewriting-to-prevent-duplicate-urls/
That will lowers my PageRank
And divvied up between the 3 different URLs instead of being concentrated into one of them.
When i checked stackoverflow implementation
I found
The 3 different URLs will directed to the same content and the same URL
for example
All next 3 links
https://stackoverflow.com/users/1824361/
https://stackoverflow.com/users/1824361/yajli
https://stackoverflow.com/users/1824361/yajli-maclo
ALL Will directed to one target URL and show its content
https://stackoverflow.com/users/1824361/yajli-maclo
The target link = {id} + {slug}
How to implement that using codeigniter
In your controller you can change the method where you'll be sending the ID to a model (with 1 argument - $id) that will return the "slug" (name) from the table for that specific ID.
With these you can then call another method in the controller that will take 2 arguments (Id and slug). This will make the link look like this: example.com/users/123ID/blaSlug
So if you access the first method, he will do the job and go to the second method.
Hope this helps
Cheers

Html.ActionLink where id is URL path causes 404

I have limited knowledge so beat me up as needed.
I have created a controller using the EF with ASPX(C#) views. I inherited this setup.
The PK in the target table/EF is an actual URL. So when you click the link ActionLink feeds the URL and I receive a 404.
Html.ActionLink("Edit", "Edit", new { id=item.ImagePath })
So id= /foldername/foldername2/image.jpg
This causes the browser to try and load the resource.
Can someone give me a clue how to process this "id" accordingly?
Have you changed your routing to accept this sort of id?
If not then you will need to go into your global.asax.cs file and edit the map routes.
This should help you with that:
Creating custom routes
The EDIT action in the controller... is waiting for a string ID or Integer one?
If the EDIT action accepts strings, then you could just scape the ID's "/"... that way the routing engine will no think the ID is a URL.

friendly url in codeigniter with variables in url

I'm making a site using Codeigniter and my URL for a particular product page is like http://www.domain.com/products/display/$category_id/$product_id/$offset
$offset is used for limiting the number of pages shown per page when using the Codeigniter's Pagination library.
How I want to make it such that my URL is something more human friendly, like http://www.domain.com/$category_name/$product_name/$offset ie. http://www.domain.com/weapons/proton-canon/3
Can anyone point me the general approach? I just started learning codeigniter and is working on my first project
You can use what's generally known as a URL slug to achieve this.
Add a new field to your table, called "url_slug" or similar. Now you will need to create a slug for each product, and store it in this field.
CI has a function in the URL helper - url_title($string) which will take a string, and convert it for use in URL's.
For example My product name would become my_product_name.
Now, in your method, you can either - keep the product_id intact, use this as a parameter for your method to show specific products, and use the slug for human friendly links, or you can just use the url_slug to refer to products.
Your URL may look like:
www.domain.com/$category_name/$product_id/my_cool_product/$offset
or it could look like
www.domain.com/$category_name/my_cool_product/$offset
with no ID. the choice is yours, but the url_slug may change - the ID won't. Which may have SEO impacts.
Regardless, your method needs to look something like:
function display_product($product_id, $url_slug, $offset) {
// do what you gotta do...
}
You can then use URL's like the above.
You will need to use URI routing as well, as the example above will attempt to look for a controller called $category_name and a method called my_cool_product, which will of course not exist.
See URI Routing for further info.

Resources