I have a db with a buch of urls. The values were entered by users, so it might be something like www.domain.com or http://www.domain.com or stackoverflow.com or https://something.com
I'm retrieving that data and creating links in a html page so people can click and be redirected to that url.
If i get the url from the page , i'll have either:
1.<a href="www.domain.com">
or
2.<a href="http://www.domain.com">
in the second case it works, but the first it doesn't.
Is there a way to make it always work?
thanks!
The www. bit is not special at all, people rely on an automatic correction feature of most browsers to prepend it if the host does not exist. To replicate this, you need to run a program that attempts to resolve each of the host names in your database, and retries with an extra www. if that fails.
The http:// bit is easy: if it is missing, add it.
There are two ways to handle this situation:
First, validate the user input. At the time a URL is submitted, validate it (preferably on the client side via Javascript) to ensure it has the required elements.
Second, in your code, you can use a regular expression or even simple pattern matching to ensure that the string starts with 'http://' or 'https://', and prepend it as needed.
The implementation details vary from language to language, but the concept is the same.
Related
I would like to rewrite an URL purely using Yii2, without relying on a webserver (nginx/apache).
Example. I would like to "rewrite" a url such as [POST|PUT|GET] /v2/book/author into [POST|PUT|GET] /v2/document/author.
My first idea was to use UrlManager's $rules, but those are not really rewriting the URLs, they map URLs into routes, so as soon as the first one matches, the chain terminates.
URL rewriting needs to happen before UrlManager even begins processing the routes.
My second idea was to create a custom UrlNormalizer which simply substitutes the incoming URLs. This sounds better, but I don't know if it will work.
What is the right way to do this?
Urls are automatically created by Yii if you don't specify it.
By default <module>/<controller>/<action>/<param>
If you have a problem, where you would have to refactor the whole code for an url change, then yes, UrlManager it is. Url::to() uses your url config to adjust your <controller>/<action> identifier into an actual url. If you hardcoded the urls then you have to change the urls manually.
But you should be able to create to create a matching pattern to catch v2/book/author
I tried this in my code, and it worked:
So this should work as well
I am trying to pass a value using a link.
For example, if I want to add an email and password for a user to Sign In straight away in the RainLoop webmail.
I am trying using
http://demo.rainloop.net/?RainLoopEmail="new#email.com"&RainLoopPassword="12345"
or
http://demo.rainloop.net/?RainLoopEmail="new#email.com"&RainLoopPassword="12345"#ID
Is this possible to do?
It is possible but you will have to rewrite the rainloop PHP files by yourself. Also parsing passwords via the GET method is a very bad idea. Get commands will stay in your history so everyone who types in
demo.rainloop.net will see the ?RainLoopPassword="12345" also. It's not recommended, but possible. Another safer solution will be using the POST method. I suspect you will use this for you bookmarks or something? You can make an AJAX page which sends a POST request with the username and password to demo.rainloop.net. This way nobody will see your passwords and the effect is the same.
EDIT: For using an AJAX page you have to own a webserver, or register on a free hosting like http://freehostingnoads.net
I'm assuming that html pages essentially extract a root path by stripping the contents before the first single slash char.
Now Given that assumption, can we tell an html page to use a different root? for example, if I have a proxy that is the root, and the proxy has a slash in it:
http://localhost:8080/proxy1/
which I want to use, rather than the normally computed root:
http://localhost:8080/
Is there a way I can modify the way my page computes its own root? i.e.
http://localhost:8080/<ROOT=http://localhost:8080/proxy>
note the last url is of course, a totally made up construct to imagine/illustrate the end goal...
IF this is impossible, which I suspect it is, what is the more general way of dealing with a proxy that has slashes in it?
After thinking some more about this, really there are a few ways to solve the problem addressed here. Here are two:
1) Give up on the complex proxy with multiple slashes in it, and just map your proxy to a domain name
Since the "The forward slash (in an absolute url) is automatically replaced with the transfer protocol and domain name of the current website (from http://www.motive.co.nz/glossary/linking.php?ref)", it will just work if your web app uses absolute urls properly.
2) Embed a root URI in your application options
This can be instrumented to tell a web server that "when you get requests to /, forward them to /x/y/z". As an example, the prometheus monitoring system provides such an option so that the application can set the root for all requests dynamically.
...There are likely other valid solutions/answers/comments on this general problem as well.
I want help understanding as to what the (!) mark means when put infront of an URL like
http://192.168.1.44/!
When i enter the url on the browser it display the directories. Right on the top first is a file which is named (!). When i open the link there is a php script which is basically connecting to mysql using the username and password supplied in the script. Then in rest of lines there are some sql statement which is no major coding just some kind of script to display list of employee with their pictures from erp database.
I see a point in script code but i don't see why its put as (!) and what does it actually do? Can someone please tell me its programing significance and otherwise please.
Thanks
There is nothing inherently special about the ! character in URLs. It is often used by various web frameworks to denote "dynamic pages", or a page that is generated mostly with AJAX requests.
I believe google will index pages ending in !# as normal pages to allow for this, but other than that, it has no special meaning other that what a programmer has given it.
I wan't developers who embed my webapp to be able to pass a param in the url like ?style=dark which will alter the css accordingly. Is there a better way to keep this setting as the user navigates than appending ?style=dark to all links?
I've considered cookies etc. but if one user is viewing two pages which embed my app with different themes then one will override the other.
I'm using Python/Django.
If you neither want to use Cookies nor Sessions and do not want to embed it into URLs, the only alternatives which comes to my mind are:
First the most generic: Use a dummy domain in front. Instead of www.example.com use h**p://THEME.example.com/PATH. This even works for HTTPS if you own a wildcard SSL for *.example.com.
A second variant would be to create a Basic-Auth-Handler which uses the Theme as the username with a dummy password. The URL then can look like:
h**p://THEME#www.example.com/PATH
However I am NOT sure what happens if a user connects to the same site with two different themes in the Basic-Auth-case. Also it is somewhat tricky to make the site available for search engines if it is behind an authentication handler. This is because you MUST have an auth-handler today to circumvent the Anti-Phishing-protection in modern browsers.
Note that with both methods you can only have one parameter easily. The password does not count and there are browsers out there which do not accept a wildcard SSL cert *.example.com for PARAM1.PARAM2.example.com.
I'm not exactly sure, but anyway you would have to pass this variable to your site. With that I mean, that there is no difference if you add ?style=dark to your href's, or rel="dark" to your <a>'s for use with javascript. keep in mind that it's just an example
Ofcourse you can always work on that AI to predict what the user wanted at the specific moment. hehe
I'm sure you can use a Session for this kind of thing, not? The first time the values are provided via the Querystring you add them to the Session and then retrieve them from the session in the future.