I've switched in my wordpress blog from urls like this:
/blog/2012/01/01/how-to-build-a-website
To shorter urls like this
/blog/?p=123
Wordpress has a search engine who works like this
/blog/search/?s=how to build a website
And search for the s params.
I'm trying to use .htaccess Redirectmatch to redirect all the old urls to the search url with the title of the post as the s params.
So if the user serf to
/blog/2012/01/01/how-to-build-a-website
should be redirect to
/blog/search/?s=how to build a website
I've coded this
Redirectmatch blog/\d+/\d+/\d+/(.+) http://www.mysite.com/blog/?s=$1
But this regex grap the whole string after the last / within the - symbol inside it.
In this way if a user serf to
/blog/2012/01/01/how-to-build-a-website
Will be redirected to
/blog/search/?s=how-to-build-a-website
while I want the user redireced to
/blog/search/?s=how to build a website
How can I write the regex to do this?
EDIT:
Yes guys, I know that this kind of urls are ugly :) But I just would know how to do it, because behind this there are some technical issues I'm trying to solve..
Please don't do this. I know it can seem tempting to go for short URLs; after all, you get things like TinyURL and such. Isn't it better to have /blog/?p=123 than /blog/2012/01/01/how-to-build-a-website?
No. It's not.
The reason is because when someone posts a link to your blog article, the longer URL means something. It tells the person how old the article is. It gives the title. It helps people find your article; after all, the URL is given a lot of weight by Google when indexing your site.
URLs used to be built for computers. Something like /blog/?p=123 is perfect for computers; it's easy to parse, it doesn't require any extra database lookups. You can write two articles named "How to Build a Website" and the blog engine doesn't have to make sure it adds a -2 on the second one. It maps easily to the actual structure of files on the server, without making up structure in the URL.
But we've realized since that URLs can be built for humans, too. The URL /blog/2012/01/01/how-to-build-a-website has a form that can be easily understood by humans. Sure, it's a bit longer to type, but all the bits you're typing are easier, and most URLs are copy'n'pasted anyway or just clicked on. It's more work for the computer, sure, but it's worth it. It makes the Internet friendlier.
So I'm sorry, but I won't help you. :)
Related
I am developing a project in Coldfusion with CFWheels MVC Framework with URL Rewriting enabled. It involves user registration and each user should be presented as username.domain.com instead of www.domain.com/users/username. Moreover once I am on username.domain.com all child pages should work as:
username.domain.com/page1
username.domain.com/page2
username.domain.com/search?k=xyz
... etc
which I am unable to achieve.
I have updated my DNS settings of the particular domain so that *.domain.com all point to the same host. What am I still doing? I found this configuration , but I have not figured out how to implement it.
Sorry this is more of an extended comment than an answer
The code has a name of coldfusion-subdomains.cfm but it looks like something that would go into application.cfc. If you look at https://github.com/cfmaniac/CF-SubDomains , it states
CF-Subdomains is a snippet of code (best used in your OnRequest Method of Application.cfc) to detect and include files from a subdirectory on your server and let it act like a subdomain.
So from here, I would go to the cfwheels documentation so see if it does anything special with OnRequest()
I don't see anything that wraps around OnRequest(), so maybe it can be used as is
You may also want to consider url re-writing instead
http://docs.cfwheels.org/docs/url-rewriting
I am using redirectTo() function with params to redirect to another pages with a query string in the url. For security purpose this does not look appealing because the user can change the parameters in the url, thus altering what is inserted into the database.
My code is:
redirectTo(action="checklist", params="r=#r#&i=#insp#&d=#d#");
Is there anyway around this? I am not using a forms, I just wish to redirect and I want the destination action/Controller to know what I am passing but not display it in the url.
You can obfuscate the variables in the URL. CfWheels makes this really easy.
All you have to do is call set(obfuscateURLs=true) in the config/settings.cfm file to turn on URL obfuscation.
I am sure this works with linkTo() function. I hope it works with RedirectTo() funcation as well. I do not have a set up to check it now. But if doesn't work for RedirectTo(), you can obfuscateParam() and deObfuscateParam() functions to do job for you.
Caution: This will only make harder for user to guess the value. It doesn't encrypt value.
To know more about this, Please read the document configuration and defaults and obfuscating url
A much better approach to this particular situation is to write params to the [flash].1 The flash is exactly the same thing as it is in Ruby on Rails or the ViewBag in ASP.Net. It stores the data in a session or cookie variable and is deleted at the end of the next page's load. This prevents you from posting back long query strings like someone that has been coding for less than a year. ObfuscateParam only works with numbers and is incredibly insecure. Any power user can easily deobfuscate, even more so with someone that actually makes a living stealing data.
I want to insert a URL filter and I would like the URL to be hard to dechiffre.
For example .*porn\.* in a way maybe that it uses the ASCII code for the letters in hex form .
Of course, the example is obvious and I definately will leave that one as it is ;)
But for the others I would like them to be hard to read!
Thx!
You can use the $_GET function in PHP to pull an ID out of the URL and display it that way, similar to Youtube with their "watch?v=". I recently did one using "?id=49" (I only have a few pages ATM, I will have about 70 soon). What I did is use a database with a song_id to index the information. I use the same basic layout, but you can use the ID to access information wrapped in PHP so that it doesnt get sent to the browser but will still display the page you want.
Or if you really want it to look crazy, you could use a database using the SHA() or MD5() function to encrypt it.
and your display will look like /page.php?id=21a57f2fe765e1ae4a8bf15d73fc1bf2a533f547f2343d12a499d9c0592044d4.
I'm new to Django and I have a BIG problem. I don't like the "url pattern" philosophy of Django.
I don't want my pages to look like
http://domain.com/object/title-of-object
I want
http://domain.com/title-of-object
and of course I will have more than one type of object.
Is there an elegant way to achieve this with Django (not using hard-coded urls)?
Thanks!
Ever wondered that, if what you want to do seems so hard to acheive, you're doing it wrong? What is so wrong with /foo/name-of-foo/ ?
I'm trying to imagine your use-case and wondering if you need 'human' URLs for only a handful of pages. If so, it would work to go with the /foo/slug-for-foo/ approach but then use the django.contrib.redirects app to support hand-written URLs that redirect to the saner, more RESTful ones?
It is possible. You'll have to create one catch-all URL pattern, for which you'll create a view that will search all possible object types, find the matching one, and process and return that. Usually, this is a bad idea.
I am working on a DotNetNuke application using the iFinity URL Master module. (that may be irrelevant, as a solution may be platform independent)
What I have is a site with addresses based on language.
so
www.thesite.com/en/products/towels/redtowel
is the english version and
www.thesite.com/de/products/towels/redtowel
is the german version.
What I need to do is allow a user (who has already visited the site and set a cookie with their language) to be able to go to www.thesite.com/products/towels/redtowel and get to www.thesite.com/en/products/towels/redtowel if their cookie is set to english, and /de/products/towels/redtowel if it is set to german.
How would I do this?
if it was me and i didnt want to spend a lot of time programming I would look at something like this
http://www.snowcovered.com/snowcovered2/Default.aspx?tabid=242&PackageID=10059
then it could do a redirect based on the cookie - otherwise with iFinity I think you can do that sort of but not exactly. (I may be wrong on that - not a fan of iFinity url rewriter)