How to rewrite url in codelgniter - .htaccess

Hello First i tell all of you that in codelgniter framework i am new and i have a problem related to my url the url looks like this
http://www.vacationplannersnetwork.com/search/name/france
but i want my URL looks like this
http://www.vacationplannersnetwork.com/france
I do search engine optimization of this website so i want this type of structure ,so if anyone knows then please help me its highly recommended.thanks in advanced.

It can be done over rerouteing.
In your APPPATH . 'routes.php' file add this line:
$route['(:any)'] = 'search/name/$1';
Since you want to have first URI segment matching your results, you would need to add other specific routes before that one. For example:
$route['contact-us'] = 'public_controller/contact_method';
$route['aboout-us'] = 'public_controller/aboutus_method';
/*
* other routes
* here
*/
$route['(:any)'] = 'search/name/$1';
Docs.
Also, don't forget to change links anchor in view files if needed (for static pages/variables).

Just use
$route['france'] = 'search/name/france';
then in <a> should bee
<a href="<?php echo base_url()?>france

Related

Url.PageLink Helper in razor pages

When I set #Url.PageLink("Project") on a page it generates a link like "http://localhost:5236/Project". But when I set the route parameter in the "Project.cshtml" page like:
#page "{id}", link #Url.PageLink("Project") returns "http://localhost:5236/?page=%2FProject".
I can't understand why. How it works?
How to generate a relative path with a parameter that is set in javascript.
Like:
a.href = '#Url.PageLink("Project")'+'/123';
If you want to add a parameter to url in js,you can try to use Url.Page():
a.href= '#Url.Page("Project")'+'/123';

How to redirect a wrong url with the same pattern that a user messed up in django, without javascript

assume the following:
Your model has: Products.slug
urls: path('<int:id>/<slug:slug>/', views.product_detail, name='product_detail'),
views: products = Products.objects.get(id=id, slug=slug)
Someone goes to /products/1/brazil-nuts/, and it goes to the right page.
But then someone copy/pastes the url wrong to: /products/1/brazil-nu/
Then you get a DoesNotExist error... Now you could "fix" this by not forcing the slug=slug argument in your query, but then the url is incorrect, and people could link from /products/1/brazil-nu-sjfhkjfg-dfh, which is sloppy.
So how would I redirect an incorrect url to the correct one with the same url structure as the correct one (only id and slug arguments), without relying on JavaScript's window.history.pushState(null, null, proper_url); every time the page loads?
I've already tried making the same url pattern to redirect, but since django uses the first pattern match, it won't work no matter where you put the url in your list.
Just update your view:
products_q = Products.objects.filter(id=id, slug__startswith=slug)
products_count = products_q.count()
if products_count == 1:
product = products_q.first()
return reverse_lazy('product_detail', args=[product.id, product.slug])

Python Requests: Use * as wildcard part of URL

Let's say I want to get a zip file (and then extract it) from a specific URL.
I want to be able to use a wildcard character in the URL like this:
https://www.urlgoeshere.domain/+*+-one.zip
instead of this:
https://www.urlgoeshere.domain/two-one.zip
Here's an example of the code I'm using (URL is contrived):
import requests, zipfile, io
year='2016'
monthnum='01'
month='Jan'
zip_file_url='https://www.urlgoeshere.domain/two-one.zip'
r = requests.get(zip_file_url, stream=True)
z = zipfile.ZipFile(io.BytesIO(r.content))
z.extractall()
Thanks in advance!
HTTP does not work that way. You must use the exact URL in order to request a page from the server.
I'm not sure if this helps you, but Flask has a feature that works similarly to what you require. Here's a working example:
#app.route('/categories/<int:category_id>')
def categoryDisplay(category_id):
''' Display a category's items
'''
# Get category and it's items via queries on session
category =session.query(Category).filter_by(id=category_id).one()
items = session.query(Item).filter_by(category_id=category.id)
# Display items using Flask HTML Templates
return render_template('category.html', category=category, items=items,
editItem=editItem, deleteItem=deleteItem, logged_in = check_logged_in())
the route decorator tells the web server to call that method when a url like */categories/(1/2/3/4/232...) is accessed. I'm not sure but I think you could do the same with the name of your zip as a String. See here (project.py) for more details.

How to create absolute links in Node.js?

I'm using Node.js with Express, Connect, and Jade. I want to provide an absolute link to a route in my application, but I can't find how to do this. I must be missing something, because this seems like a simple task.
I can do this: /myroute
But what I want is this: http://localhost:3000/myroute
There must be a helper somewhere that does this, right?
I created my own helper for this, which doesn't feel like the greatest solution.
Helpers = {
toAbsolute: ( url, req ) ->
'http://' + req.headers.host + url
}
DynamicHelpers = {
req: ( req, res ) ->
req
}
exports.Helpers = Helpers
exports.DynamicHelpers = DynamicHelpers
I add the helpers in my app.coffee file:
helpers = require './helpers.js'
# Helpers
app.helpers helpers.Helpers
app.dynamicHelpers helpers.DynamicHelpers
In my [jade] view, this is what I do to get an absolute URL from a relative URL:
| link text
There's no 'helper', but you could write your own by injecting req.query variables into the jade local variables for the route.
Personally, I'd do it client-side using window.location.origin.
update: actually, this only seems to work if req is from a POST, not a GET. :(
update 2: ugh, it's not even consistent across browsers. and neither is tim's. To find the solution I ended up using, google "window.location.origin considered harmful".
req.headers.origin appears to return something like 'http://example.com:1234' when the browser hits 'http://example.com:1234/something'.
this seems to be the express equivalent to #timoxley's client-side solution. :)
It's only a little bit simpler than yours, but it removes the need for a literal 'http' (or https).

Is it possible to link a cell In Excel to a local file with a querystring?

I had wanted to put a solution onto a thumb drive or dvd to be distributed as needed. I have a couple html pages with javascript to display photos and some other info. I also have an excel spreadsheet (2003) that I wanted to link to the html page. However when I try to use a querystring I get a warning from excel stating that it "cannot open the specified file."
edit: I use javascript to parse the querystring and load a specific photo and some info.
This does not work:
=HYPERLINK("site_photos.htm?p=1", "photo 1")
This works:
=HYPERLINK("site_photos.htm", "photo 1")
Any help here would be greatly appreciated.
edit:
Okay, I've tried using ThisWorkbook.FollowHyperlink procedure using the extrainfo and not using the extrainfo parameter. This did not work. I also tried using a shell command. This also did not pass the querystring either. It looks like I will need another solution.
edit:
Here's the javascript function used to retrieve the querystring. The querystring is not in the window.location.href so this will not work when called.
function parseUrl(name)
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexStr = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexStr );
var results = regex.exec(window.location.href);
if( results == null )
return "";
else
return results[1];
}
Whether it is possible to perform the original task or not, I have opted for a different solution. I will use image controls to view the photos and other controls for navigation.

Resources