resolving urls to some other url for development purposes - url-rewriting

I am working with both asp and asp.net pages together. I wanted to host the application in my local iis (v5.1) but later learned about iisexpress suits my needs. But irrespective of whether I use iis 5.1 or iis express I seem to have an issue.
The asp page which I work with refers to static resources (css, javascript, etc) which reside in a different virtual directory. For e.g. a css file include would look like this.
<link rel="stylesheet" href="/common/include/style/css.css"/>
If such a thing is supposed to run from the test environment then the above url would resolve to:
http://testing/common/include/style/css.css
This is in contrast where my main application would reside. That would look something like:
http://testing/myapp/default.aspx
Now if I run iisexpress in say port 8082, and there is an inbound request like:
http://localhost:8082/common/inlcude/style/css.css
it will hit a 404 error. Is it possible to instruct iss or iis express to resolve such url (which begin with /common/...) to say http://testing/common/...
Update (May 31st 2011, 7.04 PM IST):
Been doing some research on what url rewriting is, and from the examples I have come to understand a few things. I am not sure if what I want is url re-writing, per se. Again taking the iisexpress analogy, I know there will be an inbound request uri like:
http://localhost:8082/common/inlcude/style/css.css
But I want this to be actually served by the following uri:
http://testing/common/include/style/css.css
The former uri doesn't exist in the folder which I have virtualized using iisexpress.
Do I need url re-writing here?
Further, in ASP, I have include lines like:
<!-- #include virtual="/common/include/classes/utils.asp" -->
Even these things are supposed to be resolved to their corresponding http://testing/... counterparts.
ps: I am doing all this is iis 5.1

In ASP.NET 2.0 onwards you can use the tilde operator (~) which is used to specify where your application is rooted. For example:
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
Would produce a relative url:
<link href="Styles/Site.css" rel="stylesheet" type="text/css" />
This works fine for ASP.NET pages.
Classic ASP and static HTML pages are a different story and one or more of the following mechanisms would have to be used:
Make everything relative. If you have a page or ASP script in the root of the site, instead of specifying /common/include/... specify common/include/.... If you have a page or ASP script in a subfolder the you'd reference your CSS by way of ../common/include/..., i.e. parent paths. The deeper the folder structure the more ../ parent paths you have so managing these relative paths can get messy. Also, although not common these days, some shared hosted servers disallow parent paths.
Prefix your CSS paths with a variable containing a path prefix. For example:
<link rel="stylesheet" href="<%=Session("RootPath")%>/common/include/style/css.css"/>
In production you'd globally set the session value RootPath to /MyApp, but for testing leave as an empty string. You could do this in Session_OnStart in your global.asa. You could also use an application wide value Application("RootPath") instead. This would only work for ASP pages.
URL Rewriting - if you have static HTML pages then URL rewriting can come to the rescue. You would rewrite the absolute url's which work on your dev PC to the path used on the production server. So basically every time you see a href="/common/... you'd rewrite to href="/myapp/common/.... IIS6 doesn't support rewriting out of the box, you'd need a third party tool such as Iconics IRF or HeliconTech's ISAPI_Rewrite3. IIS 7.x does support URL rewriting through the URLRewrite Module 2.0.

Related

how to access website stored on xammp via static public ip

I have designed a website. Almost all settings are done such as port forwarding in router etc. The website is also accessed on any computer through internet using static public ip but displays text only without any css effects, images etc.
If the CSS styles, images, JS files, etc. are not displayed outside the localhost (from your IP address), it must be because when you specify the URL or location of those files, you give an absolute URL which works just for localhost.
For example, if you have
htdocs/
index.html
css/
stylesheet.css
img/
logo.jpeg
slider-1.png
slider-2.png
slider-3.png
This will work just in localhost (the computer where xampp is installed):
<link rel="stylesheet" href="http://localhost/css/stylesheet.css">
<img src="http://localhost/img/logo.jpeg">
ETC.
If you want it to work also outside your computer you should use relative paths:
<link rel="stylesheet" href="/css/stylesheet.css">
<img src="/img/logo.jpeg">
ETC.
This is because the HTML code is executed in the client side (in the person who visits your page's computer) so they can't access your files through localhost...
I hope this helps you, I was going to ask you which type of URLs do you use through the comments before answering but I can't add any comments because of my reputation :v

Laravel 5 helper function asset different domains

In Laravel 5.0, I am using the helper function asset to show where different assets are ( css, js images etc. ). I am building a platform that shows different information depending on the url which means I cannot bind the asset to a url. I know in config/app.php it has 'url' => 'http://localhost' but I cannot change that because the url will not always be the same. Is there a way to set this up to handle the domain changing within the same application?
Assuming your assets are always going to be in the same relative path from the root of the site (regardless of the domain), you should just be able to output the URL to various assets as a relative URL. So, for example, if in your blade template you had something like:
<link rel="stylesheet" href="{!! asset('css/style.css') !!}">
you could replace it with a relative URL like this:
<link rel="stylesheet" href="/assets/css/style.css">
This should resolve correctly regardless of what domain you're on, and should also be fetched via HTTPS in the case that the user is on a secure page.
If you need something more complicated, you might consider setting a session('domain') variable or something that would be accessible from a global scope that could then be used to generate links to assets like:
<link rel="stylesheet" href="http://{{ session('domain') }}/assets/css/style.css">
If none of these work, then your situation is probably complicated enough that you'll need to provide us some more code before we can offer workable solutions.

How to give URL for Home page from Spring MVC on Heroku

I have looked and tried everywhere without success so posting this question.
Recently deployed a working Spring MVC app on Heroku platform, it was a pleasant experience for the most. How ever the spring url tag or even jstl core url tag are behaving differently on Heroku, than on my local tomacat server.
for example my links '>Sign in would be perfect resolves to http: //mydomain:port/context/signin on my local but after deploying the Heroku it would /signin as absolute path, so i quickly removed and it is working good.
However i have a home link on my nav bar that is '>Home if I remove the forward slash then the Home link is essentially point to what ever is my current url on address bar instead of context home.
Any suggestions ?
From experience what works best for me is not to hardcode your link with / on the left, but create this "root" variable on your jsp:
<c:set var="root" value="${pageContext.request.contextPath}"/>
Then in your jsp whenever you need reference root path:
<img src="${root}/resources/mycoolpic.png"/>
Other variation is you can use html <base..> tag to set where / refer to but this make your code more obscure and hard to understand. For example:
<base href="my-root">
<img src="/resources/mycoolpic.png"/>
Will actually resolve to /my-root/resources/mycoolpic.png
just after going through couple of other similar questions and answers, the below approach solved my problem on Heroku for Home page link.
created a <base/> element in <head> as below
<base href="${pageContext.request.scheme}://${pageContext.request.serverName}
:${pageContext.request.serverPort}${pageContext.request.contextPath}" />
then in jsp the code below started resolving correctly on Heroku
</s:url>'>Home
<s:url value="signin"></s:url>'>Sign in</a>
how ever for my local tomcat deployments to work i had to append an extra forward slash to the above
<base href="${pageContext.request.scheme}://${pageContext.request.serverName}
:${pageContext.request.serverPort}${pageContext.request.contextPath}/" />
since this code is only in my base template I guess I will have to live with this one file descrepency between my local and deployed versions
I would love to see any wholesome answers

Magento base url not reflecting value changed in database (missing /)

This is one of those things that on the surface of it seems very simple to resolve, but it's got me beat!
I can see from searching around that quite a few people have had this issue crop up but there seems to be no solution that I can find.
What I've done:
1. Transfered my site from the root folder into a /shop folder.
2. Changed the database entries for secure/unsecure base urls to https://www.dnabaits.com/shop/
3. Cleared out all the Cache and Tmp files.
What's happening:
The whole site is functional but no styles or scripts are being loaded because the paths in the head are missing the trailing / after shop.
So instead of getting this
mydomain.com/shop/skin/........
I'm getting mydomain.com/shopskin/........
An example Url from my page source
<link rel="stylesheet" type="text/css" href="https://www.dnabaits.com/shopskin/frontend/default/dna/css/lightbox.css" media="all" />
In your .htaccess file make sure you have this (with trailing slash):
RewriteBase /shop/
Another possibility is that your Store Configuration Scope for your Store View has a different setting. Change your Configuration Scope in Admin -> System -> Configuration -> Web and make sure your URL settings aren't customized there.

Why would images and script file paths not resolve after deployment in an Asp.Net MVC application

I have developed an Asp.Net MVC application in Visual Studio 2010. So far so good. In terms of path resolution for images and script execution, everything runs perfect within Visual Studio. As I am using the default template of MVC I am using "../../Script/*.js" kind of path. After I build the package for deployment and deploy in IIS, the images and the script references stop working. I think it might be a path resolution issue. I tried with "~/Script/.js" but it does not work either. Could somebody suggest why this is happening?
Consider using two things in any of your asp.net MVC projects.
1) Using a Layout for common site elements using _Layout.cshtml and include all your javascript and css files inside that and do not put it on the any other .cshtml pages unless necessary required. see here how to use _Layout.cshtml
2) Second thing always use #Url.Content() directive to define your paths e.g
<link href="#Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="#Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
This two way always helps you and never have problem even if you deploy package.
Hope above helps.
This type of problem we get in asp.net when we use URL Rewriting and asp.net mvc have a URL Rewriting by default.
so when you use script or urls and js then you set your path like this .
#Url.Content("~/Your Url or Your script or Your js File ") ;
i think this will help you.
MVC has built in functions that generates url's, so use those instead of hard code url
#Url.Content("~/yourpath")
When you deploy your webapp onto IIS, your site is set to run as Virtual Directory so the website root is no longer the same as the application root, MVC has
ActionLinks,Url.Contents to resolve Url's.
MSDN help

Resources