I have a website setup in IIS with 2 HTTP Headers (www.mysite.com and [blank]).
There is a virtual directory called 'blog' which points to a WordPress site - this is accessed via www.mysite.com/blog/
Any other requests (e.g. www.site1.com, www.site2.com, something.mysite.com) are handled by the same site (using the [blank] header) and rewrite rules to display the necessary information.
The problem is I don't want /blog/ to be available to anything other than www.mysite.com, as presently I can access it with any of the following:
www.site1.com/blog/
something.mysite.com/blog/
This is because we are also using BlogEngine (for user blogs) and if they set their blog directory to be 'blog' then it clashes with the WordPress one.
Ideally I'd like to be able to add a host header to the virtual directory, but can't find a way to do that, so looking for any other solutions (other than moving the WordPress blog).
Thanks in advance
You can prevent browsing to /blog on non-www.mysite.com sites using a UrlRewrite rule:
<rule name="RequestBlockingRule1" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAll">
<add input="{URL}" pattern="/blog*" />
<add input="{HTTP_HOST}" pattern="www.mysite.com" negate="true" />
</conditions>
<action
type="CustomResponse" statusCode="403"
statusReason="Forbidden: Access is denied."
statusDescription="You do not have permission to view this directory or page." />
</rule>
Related
I have a asp.net mvc website hosted on godaddy shared server. I want to write a url rewrite rule which would remove the virtual directory name.
Below are few my website URLs. All URLs works. but I want to redirect any url that has virtual directory name (breederyellowpages) in it to the root.
http://www.breederyellowpages.com
http://www.breederyellowpages.com/breederyellowpages
http://www.breederyellowpages.com/breederyellowpages/blog/other/introducing-suggest-a-feature-in-account-management
I tried to research & implement couple of ways of doing that. but its either not working or I am doing it wrong.
https://weblogs.asp.net/jhallal/remove-hosting-folder-name-from-mvc-url
Give this one a try:
<rule name="RemoveVirtualDirectory">
<match url="breederyellowpages/(.*)" />
<action type="Rewrite" url="/" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.breederyellowpages.com$" />
</conditions>
</rule>
I have several shared hosting accounts with Newtek. They told me one account can be used to host several websites, but I don't know how to do that.
They said it can be done using either an .htaccess or web.config file. And since it's ASP.NET, that suggests web.config is the way to go.
Does anyone know how to use web.config to route requests for a given domain to a subfolder? I assume that subfolder would need to be set as an application starting point, which it appears their control center will allow me to do. I just need to associate that starting point with a particular domain.
And does this sound like a reasonable approach (shy of forking out money for a virtual server)?
If the IIS URL Rewrite Module is installed, you can create a Rule to redirect the request to a subfolder based on the domain name.
<rule name="site2.com" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www.)?site2.com" />
<add input="{PATH_INFO}" pattern="^/site2/" negate="true" />
</conditions>
<action type="Rewrite" url="\site2\{R:0}" />
</rule>
Source: https://weblogs.asp.net/owscott/iis-url-rewrite-hosting-multiple-domains-under-one-site
I have an aspx page with some HTML tags
Example
Actual url
<img src="https://google.com/fp/clear.png?latitude=<latitude>&longitude=<longitude> alt="">
How do i change the domain name (google.com) to a local URL (localgoog.com), and configure web server to redirect the URL (localgoo.com) to actual url (google.com)
Since you're referring to an aspx page, I'm assuming you're running on IIS. In that case, you may install the URLRewrite module into your IIS server. http://www.iis.net/downloads/microsoft/url-rewrite
Then, within IIS management console, you may setup a rewrite rule to redirect any url coming in with the hostname of "localgoo.com" to "google.com". Once you save this rule, your web.config file will be modified to include the XML version of your rewrite rule, which then makes your app portable to other servers as well.
<system.webServer>
<rewrite>
<rules>
<rule name="RedirectToGoogle" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^localgoo.com$" />
</conditions>
<action type="Redirect" url="//google.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
The {R:0} is a captured group of anything that comes after the hostname and appends it back onto the new hostname.
I have a site that is being served out of Sitefinity CMS, at http://www.example.com/, I also have sites on the same server that are being served out of the same root location that are accessed as follows: http://www.example.com/sub-site/. All of these sub-sites are in php and resolve to specific php files such as index.php. There are a lot of these sub-sites and we're looking to remove a number of them from the server. We usually send variables in the get request to these sub-sites as follows: http://www.example.com/sub-site/?address=12&ID=22
What we want to do is set up a rewrite rule that will redirect incoming requests to non-existent sub-sites to an error page written in PHP. This rewrite rule should keep the query string intact so that we can still use those variables once the error page is reached.
Here is the re-write rule that we have:
<rewrite>
<rules>
<rule name="RedirectFileNotFound" stopProcessing="true">
<match url=",*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="errorpage.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
So this rewrite rule works terrific, in fact, it works too well. When I go to the Sitefinity site's home page all is well, but when I click on any of the links on that page, I'm redirected to the error page. I've determined that the problem has to do with dynamic server content as the Sitefinity site links look like this http://www.example.com/order/ or http://www.example.com/info/. These directories don't exist and thus, the rewrite rule catches them each time.
Is there a way that I can redirect the subsites without having the sitefinity site respond the same way?
I found this S.O. post that is addressing a similar problem, but I was unable to find much assistance there.
I want to be able to rewrite a url using url rewriting in IIS 7 whenever an anonymous user hits the home page of my wordpress site. Is there a way to identify whether the user is logged in or not as a condition of a rewrite rule?
Turns out this can be done by inspecting the cookie. In my case, I check to see whether HTTP_COOKIE contains the text 'wordpress'. If it does not, then I rewrite to a cached version of my page.
I also include a check to make sure we are on the www subdomain to avoid any conflict with another of my rewrite rules that is run when the url is on mydomain.com.
<rule name="HomePageCacheRewriteRule" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^$" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_COOKIE}" negate="true" pattern="wordpress" />
<add input="{HTTP_HOST}" pattern="www.mydomain.com" />
</conditions>
<action type="Rewrite" url="cached-home-page.htm" />
</rule>
The result is that anonymous users get the cached page, while logged in / recently logged out users see the standard page loaded by Wordpress.
Note: There are some additional checks that should possibly be added to handle some other scenarios. Here is a good article with a more robust example http://ruslany.net/2008/12/speed-up-wordpress-on-iis-70/