I am a total noob on this issue, and I wonder if I have to do that where I put the code :
In the virtual host / apache conf file ?
In a httaccess file ?
Redirect all URLs to a single entry point and parse it with a scripting language ?
What are the pro and cons ?
I'd tend to go with the .htaccess because it's easier to maintain as part of a project's files, doesn't require kicking the web server to take effect, and will typically be faster than scripting-level rewrites.
This depends on what exactly you want to do.
Rewriting rules should go in the configuration relating to the directory/site root which is typically your vhost configuration or htaccess (depending on setup).
Doing this through a script only makes sense if your redirect is based on extra information such as matching a 404 to a database of recently moved pages or a 404-URI to a search of some kind.
OK, so I put some summary of what I read on SO about it :
URL rewriting for redirection :
Better to put that in the Apache configuration. using .htaccess is the most flexible way but your Apache conf must allow it, if not, set the rewriting in the Vhost file.
URL rewriting for ressource management :
When it's about managing not found contents, access right or getting clean URL for accessing dynamic contents, you need to set the rewriting in the script file of your app since it's where you have access to the API to handle this kind of things.
So both of the ways are complementary, and you will usually use both at the same time.
.htaccess file in the directory should best place if you dont have any speed optimization concerns. And its also the way to go if your site is hosted on shared webhotel or your web application can create the htaccess files by itself.
Personally i prefer to have every configuration option in the virtualhost config file but thats good only if you have the root access.
It depends if you also need to do outbound URL-rewriting (the modification of links in the actual HTML pages themselves,) in which case, a tool like MOD_REWRITE will not do the trick for you, and you will need to use an "internal" or "native server-side" tool, in the case of Java, you would use something like PrettyFaces, or Rewrite.
These tools can also do the same type of inbound rewriting (like sending redirects to new pages, or forwarding to a new internal resource so that users do not know they are seeing an address/URL change.
My general rule of thumb, however, is that if the URL-rewrite rules need to be available when the application is running, you should use something like MOD_REWRITE, but if the rules only apply to that application itself, then they belong inside the application and you should use a native tool.
Related
I have a problem with Domino Web Server with an XPages Application which is placed behind some reverse proxy. The problem is, the proxy forwards all requests from the URL like h2tps://organization/test_server/ to the Domino Web Server.
This makes all links in the application brocken. And I don't know how to fix it.
For example, the login attempt will be redirected by the server to h2tps://organization/names.nsf?Login instead of h2tps://organization/test_server/names.nsf?Login
Have you any idea how to fix it?
When using a reverse proxy, we recommend keeping the original URL unchanged. Because many redirects, Ajax requests, cookie are closely related to URL, if the URL changes, almost must go to modify the code.
This problem is especially serious in Domino, because in a lot of Javascript code that will be used in the absolute path, for example /names.nsf. As a comparison of Java applications in general will use relative paths (for example ../login).
The actual way to achieve URL unchanged: map the domain name of the original domino server (for example test.domino.xxx), to the reverse proxy server, and reverse proxy server via http HOST header to determine forwarded to which backend server, without the need to add additional path (for example test_server).
In IBM WebSeal example, this configuration is called virtual host junctions.
Did you create a site document on the domino Server?
I have solved the problem with some efforts.
At first I have moved the DB in the folder /test_server/.
Then I have changed all static HTML links to use the /test_server/.
With the option xsp.application.context.proxy=test_server I have changed the
paths for internal XPages and Extensions Library resources.
At the end I have to add some substitution rules on the Domino
to prevent duplicated paths like /test_server/test_server/.
Now it seems to be working well.
The proposal from the proxy team was to use url rewrite on the Web Server. It can be done with Domino without doubt, but requires to develop a DNSAPI Addon (a dll written in C). And it doesn't look for me like an easy task.
Anyway, thanks a lot for your help!
I have three different domains all on the same server and I want to run the code on all three domains from one source on the same server, but not sure the best way.
Here's what I have:
domain01.com
domain02.com
domain03.com
domain04.com/sourcecode
I want domain01-03 to run the code inside domain04.com/sourcecode so the user can go to their domain and not have to go to domain04.com to see their site. I want to keep all the code inside domain04.com because I don't want to have to put the code inside each domain every time I make a code change.
For whatever reason I can't get my head around the best way to do this -- and want to do it right.
Any advice?
Thanks!
All you need to do is create a mapping on the first three sites to the appropriate directory in the fourth site, eg map /domain04 to /full/path/to/domain04/sourcecode, then refererence its CFML resources via /domain04 in CFC and include paths. The inference here is the code does need to be accessible via the file system for all sites concerned.
Note that if you also want to server non-CFML files via HTTP (eg: images, css, js), then you will also need a web server virtual directory along the same lines.
None of this requires a framework, it's standard CF / web server functionality.
Are you using a framework? One like ColdBox could make this trivial if your code is written modularly. (Disclaimer, I am affiliated with ColdBox)
If not, it really depends on what the code is. CFCs can be mapped anywhere via ColdFusion mappings. Even .cfm files can be included as long as the file systems are visible. If you're wanting to basically have complete copy of a site in another web root without duplication, I would first consider using a shared source control repo and a build process that checks it out in the appropriate places, and secondly a good old, symlink will also work .
I believe Smarty templates has functionality built in that allows you to manage your site URLs from a config file so if something gets moved, you only have to update the URL in one place. Does this sort of functionality exist in CodeIgniter? If not, any pointers or examples on how/where to add it?
For example:
Instead of hard-coding the link it would be: Settings
But where would you want to set $links so that it was available everywhere? Or is it really best to just hard code them?
Take a look at the config class. It allows you to make custom config files.
It's not entirely made for URL's but you sure can use them.
The base url should be basically right at the start of /app/config/config.php, where app is the name of your codeigniter application folder. You access it through calls to the base_url() function.
Yes, it's called Routes, configuration located at config/routes.php. Documentation
If you ask about the rendered html of the links, then your best bet would be using site_url() in conjunction with constants, for example site_url(URL_SETTINGS);, there is no built in functionality for that, but I can say I don't think that is necessary as it would be used too rarely, but it would influence performance every single load.
I'm currently messing around with making a custom MVC framework for educational (and, if it's good, actual practical) use, and I like to investigate different scenarios for possible performance boosts.
When it comes to URI routing, I'm familiar with the standard URI format of
/controller/action/id
And parsing the data out of this to control the routing wouldn't be too difficult. Now, what I'm moreso wondering about is the performance difference between having nginx parse this URI string out into a query string of some type to pass to a controller directly, so that would end up like
/foo/bar/12 => /application/foo.php?action=bar&id=12
instead of
/foo/bar/12 => /index.php?controller=foo&action=bar&id=12
or even
/foo/bar/12 => /index.php?uri=/foo/bar/12 (note that this would be encoded)
I'm aware that nginx passes the url, query string, and other things to php-fpm in other variables already, but this is just for illustrative purposes to show what I'm thinking.
Is this a stupid thing to do? I know that by defining routes explicitly in nginx would mean me needing to restart nginx every time I alter the routes in the config, which could be a downside.
So, to restate the question: When it comes to MVC routing, is there any worthwhile performance gain by having the actual webserver (in this case, nginx) itself handle the routing to the controller OR is using a standard landing script (like index.php in the root of the directory) and passing along the URI to be parsed for routing perfectly fine?
Thanks ahead of time. Also, I'm just learning about these things, so I wholeheartedly welcome suggestions on what I should be doing instead.
I wouldn't mix application logic (URL routing) into your HTTP server. Lots of PHP apps used to rely on Apache .htaccess files for this sort of thing. It ends up being a mess.
As you mention, it would require restarting Nginx to change routes, and it would also tie your application to Nginx, unless you wanted to rewrite all your rules for another HTTP server at some future date. Even worse, if you decide to scale your app out over more than one server, you'll have to repeat these rules for each upstream.
tl;dr Keep your layers separate.
When I look at Amazon.com and I see their URL for pages, it does not have .htm, .html or .php at the end of the URL.
It is like:
http://www.amazon.com/books-used-books-textbooks/b/ref=topnav_storetab_b?ie=UTF8&node=283155
Why and how? What kind of extension is that?
Your browser doesn't care about the extension of the file, only the content type that the server reports. (Well, unless you use IE because at Microsoft they think they know more about what you're serving up than you do). If your server reports that the content being served up is Content-Type: text/html, then your browser is supposed to treat it like it's HTML no matter what the file name is.
Typically, it's implemented using a URL rewriting scheme of some description. The basic notion is that the web should be moving to addressing resources with proper URIs, not classic old URLs which leak implementation detail, and which are vulnerable to future changes as a result.
A thorough discussion of the topic can be found in Tim Berners-Lee's article Cool URIs Don't Change, which argues in favour of reducing the irrelevant cruft in URIs as a means of helping to avoid the problems that occur when implementations do change, and when resources do move to a different URL. The article itself contains good general advice on planning out a URI scheme, and is well worth a read.
More specifically than most of these answers:
Web content doesn't use the file extension to determine what kind of file is being served (unless you're Internet Explorer). Instead, they use the Content-type HTTP header, which is sent down the wire before the content of the image, HTML page, download, or whatever. For example:
Content-type: text/html
denotes that the page you are viewing should be interpreted as HTML, and
Content-type: image/png
denotes that the page is a PNG image.
Web servers often use the file extension if the file is served directly from disk to determine what Content-type to assign, but web applications can also generate pages with any Content-type they like in response to a request. No matter the filename's structure or extension, so long as the actual content of the page matches with the declared Content-type, the data renders as intended.
For websites that use Apache, they are probably using mod_rewrite that enables them to rewrite URLS (and make them more user and SEO friendly)
You can read more here http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
and here http://www.sitepoint.com/article/apache-mod_rewrite-examples/
EDIT: There are rewriting modules for IIS as well.
Traditionally the file extension represents the file that is being served.
For example
http://someserver/somepath/image.jpg
Later that same approach was used to allow a script process the parameter
http://somerverser/somepath/script.php?param=1234&other=7890
In this case the file was a php script that process the "request" and presented a dinamically created file.
Nowadays, the applications are much more complex than that ( namely amazon that you metioned )
Then there is no a single script that handles the request ( but a much more complex app wit several files/methods/functions/object etc ) , and the url is more like the entry point for a web application ( it may have an script behind but that another thing ) so now web apps like amazon, and yes stackoverflow don't show an file in the URL but anything comming is processed by the app in the server side.
websites urls without file extension?
Here I questions represents the webapp and 322747 the parameter
I hope this little explanation helps you to understand better all the other answers.
Well how about a having an index.html file in the directory and then you type the path into the browser? I see that my Firefox and IE7 both put the trailing slash in automatically, I don't have to type it. This is more suited to people like me that do not think every single url on earth should invoke php, perl, cgi and 10,000 other applications just in order to sent a few kilobytes of data.
A lot of people are using an more "RESTful" type architecture... or at least, REST-looking URLs.
This site (StackOverflow) dosn't show a file extension... it's using ASP.NET MVC.
Depending on the settings of your server you can use (or not) any extension you want. You could even set extensions to be ".JamesRocks" but it won't be very helpful :)
Anyways just in case you're new to web programming all that gibberish on the end there are arguments to a GET operation, and not the page's extension.
A number of posts have mentioned this, and I'll weigh in. It absolutely is a URL rewriting system, and a number of platforms have ways to implement this.
I've worked for a few larger ecommerce sites, and it is now a very important part of the web presence, and offers a number of advantages.
I would recommend taking the technology you want to work with, and researching samples of the URL rewriting mechanism for that platform. For .NET, for example, there google 'asp.net url rewriting' or use an add-on framework like MVC, which does this functionality out of the box.
In Django (a web application framework for python), you design the URLs yourself, independent of any file name, or even any path on the server for that matter.
You just say something like "I want /news/<number>/ urls to be handled by this function"