I have http://thewebsite.com/blah/category/hello.html
We need to redirect any url with /blah/ to the root of the site so that the new url is
http://thewebsite.com/category/hello.html
How can we do this with iis7? Thanks in advance.
Edit: I have just learned that our problem is not about 301-redirection but rather about url-rewrite. We are actually using wordpress with permalink /index.php/%category%/%postname%.html and the url goes this way : http://thewebsite.com/index.php/categoryname/hello.html. So using Url Rewrite on IIS7, how can we make the url to http://thewebsite.com/categoryname/hello.html? Thank you so much!
You can use the URL rewrite module as Lex Li described - it's quite powerful. It's an add-on that you can download and install into IIS7. For this example though, you can also use the "HTTP Redirect" feature which is included out of the box.
You will need the "blah" directory to exist physically under the root directory of thewebsite.com. It can be empty, but it has to exist. It can be an ordinary directory; it doesn't have to be a virtual directory or an application.
From the left-hand tree view, select the "blah" directory, and then go to features view. Double-click the "HTTP Redirect" icon. Check the "Redirect requests to this destination" box, and type "http://thewebsite.com". Leave both of the checkboxes under "redirect behavior" unchecked. Under "status code", choose "Permanent (301)". Then click the "Apply" link under "Actions" at the right.
This will redirect everything under http://thewebsite.com/blah/ to the corresponding URL under http://thewebsite.com/. It will also work for subdirectories under "blah", such as your "category" example.
Related
I'm having trouble with my URL Rewriting; IIS keeps adding the folder name to the url.
E.g. my.site.com/Login/ gets re- written to my.site.com/MY/Login
The frustrating thing is that the my.site.com/Login/works but whenever a link is clicked it adds the /MY/ to the url.
Does anyone know how to resolve this?
Existing re-write rule: (http(s)?:\/\/)?my.site.com
Rule I'm playing with (not finished) to try and detect the /MY/ and redirect to the 'proper' url
(http(s)?://)?(www.)?my.site.com/MY/
Thanks!
In IIS7 I right click on the site and choose "Switch to content view" then add a text file called test.txt right click again and switch to features view. Double click the http redirect icon and see it's not forwarding.
Right click the site and switch to content view again now right click on test.txt and choose browse only to be forwarded to some other site that gives me 404 for not having /test.txt.
I don't know where to look anymore as the settings mentioned above would indicate there would be no forwarding but opening the file proves that it does.
When using forcecors plugin for firefox and making a ajax request to the text file I can see the response header: Location http://some_other_site/test.txt.
Hope it's something simple.
[update]
In the application I checked out the settings under "Url rewrite" and found a rule that redirects. Removed this rule and stopped started IIS but it's still forwarding. Could not find anything under System32\inetsvr\config that would indicate redirecting.
After removing the url rewrite rule and testing in the browser it kept on forwarding because I think my browser remembered it was moved. Cache settings on IIS should check if file has changed after it was last cached (I think last modified headers) but somehow a redirect works differently. Did not clear my browser cache and even doing that could still cause a problem with proxies caching it.
What I did was opening it this way:
http://develop.mysite.com/test.txt?refresh=newValue
Like magic I wasn't redirected and it works now. Start FF with another profile and see if that solves the problem as the new profile should not be aware of the sites response being "permanently moved" by a previous request.
I am not very familiar with IIS7 and I need to create a server variable so that I can access it within my PHP code. I can easily accomplish this in Apache by using:
SETENV variable_name variable_value
in the .htaccess file. However accomplishing this in IIS seems to be a bit of a secret. I have looked online for info and the closest thing I can find states using the URL Rewrite Module using these steps:
Clicking on View Server Variables
Click the Add link and enter the variable name
Go back to rules and click the View Rewrite Maps
Click Add Rewrite Map and enter the default value.
Restarted the server.
Full docs can be found at: http://www.iis.net/learn/extensions/url-rewrite-module/setting-http-request-headers-and-iis-server-variables
I followed that but it still doesn’t work. Any ideas how this is done? Is it even possible to do this in IIS? All I want to do is set up a server variable with a static value.
example: $_SERVER['MY_VARIABLE']
Thanks.
In IIS Manager click on your machine, open the "URL Rewrite" icon from the "IIS" icon group.
Under "Actions" (on the extreme right) click the innocuous little "View Server Variables" link, disregarding "Manage Server Variables"
In the "View Server Variables" screen's "Actions" (on the extreme right) click "Add..."
I solved this by using the PHP auto_prepend_file directive. More information can be found here: http://www.php.net/manual/en/ini.core.php#ini.auto-prepend-file
Just create a file that adds the desired value to the $SERVER array, set that as the auto_prepend_file and you are good to go. This will work with any server, not just IIS.
The other answers clearly work, but seems messier than the way I found.
Go to FastCGI settings, where you have the PHP exe configured (per the original question)
Right click on ...\php-cgi.exe, select "Edit"
Then choose the ellipses next to "Environment Variables"
Then you can click add/remove and edit your variables.
We're using IIS7 and ASP.NET 3.5.
We have updated our website with new pages. Now, there are many links on the internet pointing to our website, however many of those links are now broken due to a change in our directory structure for our new website.
I need to have a number of requests, 301 redirected to the "new page." Many of the old pages are simply directory URL's such as:
/services/softwaredevelopment
/products/geographicdata
/sitemap
/company/termsofuse
I have written some code in the Global.asax file to catch the url's, parse them out, and redirect them. However, when there is no file reference (.aspx), the URL's are not caught by my ASP.NET application.
It seems then, that these redirects need to be created in IIS7.
Now, the urls above are at a directory level (they are not directly requesting an actual .aspx page)... I can redirect a 'directory' request to another 'directory' by using virtual directories.... But I cant redirect a directory request to an actual .aspx file
Here are some of the types of redirects I need to make:
==========
Old: /services/softwaredevelopment
redirect to: /services/custom-software-development.aspx
============
Old: /sitemap
redirect to: /sitemap.aspx
============
Old: /company/termsofuse
redirect to: /company/termsofuse.aspx
=============
Old: /company/careers
redirect to: /company/careers.aspx
=============
Old: /services/
redirect to: /services/custom-software-development.aspx
=============
Can someone shed some light on how to accomplish this? Please let me know if you have any questions. Many thanks for your help.
Tim
One quick and dirty option is to create default.aspx redirect pages in the folders you have listed. For example, to handle /services/softwaredevelopment, create a file default.aspx at /services/softwaredevelopment/default.aspx with the following:
<%# Page Language="C#" Inherits="System.Web.UI.Page" %>
<% Response.Redirect("/services/custom-software-development.aspx"); %>
This solution is only practical if there are only a few redirects, as it clutters your project with code files that do very little. A better solution for a large number of redirects is to use IIS 7's native URL rewriter.
Check out "HTTP Redirection in IIS 7 on Windows Server 2008" http://www.trainsignaltraining.com/iis7-redirect-windows-server-2008
You should be able to do most kind of redirect by configuring IIS rather than coding.
What is this error when I SiteMapPath and Configure whit siteMap.of course when I upload my website,I showing this error : "The page cannot be found
The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.
Please try the following:
Make sure that the Web site address displayed in the address bar of your browser is spelled and formatted correctly.
If you reached this page by clicking a link, contact the Web site administrator to alert them that the link is incorrectly formatted.
Click the Back button to try another link.
HTTP Error 404 - File or directory not found.
Internet Information Services (IIS)
"
What Do I do that SiteMap work correctly ?
Here is a critical question and something to try:
Does the website work on your development machine?
If it does work then check the url for the pages in the SiteMap. If the URL for the pages in the SiteMap reference a physical directory such as "C:\mySite\MyPage.aspx" then that is the most likely cause. You want to ensure that the URLs refernce the page location through a relative path like "~/MyPage.aspx".
If it does not work, then verify that there are no typing errors in the URLS. Once you getting it working on a local development environment using relative paths then the chance of it working on a remote machine should go up considerably.