web.config using an absolute path - url-rewriting

I need to use a rewrite rule for a url(www.example.org/download.php) to hit another file called download.php, that is not in my root directory, but located in C:/repo/other_directory/test/download.php, however, it is not working. I have to use an absolute path in the rule. Any help on this would be greatly appreciated. My code is below:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule placestoswim" stopProcessing="true">
<match url="download.php" ignoreCase="false" />
<action type="Rewrite" url="C:/repo/other_directory/test/download.php" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

I dont think this will work the url paramter of a rewrite is expecting a URL not a file system path.
If you cant move that location, can you create a virtual directory inside your existing site called downloads, and point its web root at your immovable folder C:/repo/other_directory/test/? Then in your web.config setup a rewrite to use this newly created path ~/downloads/download.php as the destination for your rewrite for ~/downloads.php

Related

URL rewrite from trailing string to GET variable

I've searched for this, but can't seem to come up with the right search terms to find - seems it would be a common question.
WIMP, IIS version is 8
I want to come up with a rewrite rule:
Incoming URL: http://example.com/1a2b3cdef
Rewritten to: http://example.com?p=1a2b3cdef
Note, the start of this url will always be "http://example.com/" (not the real domain name), that will never change.
From there my default document of index.php will retrieve the GET variable p.
Any help is greatly appreciated.
This is the configuration that can be applied in web.config.
<defaultDocument>
<files>
<add value="index.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="rewrite" enabled="true">
<match url="^[_0-9a-z]+" />
<action type="Rewrite" url="?p={R:0}" />
</rule>
</rules>
</rewrite>

web.config to route all request to index.php except for physical files and directories

im trying to upload a php script to windows iis server
in php script we have a htacess file which routes all the request to index.php so we can have
site.com/something
instead of
site.com/index.php?/something
but it doesnt work on the windows server so i tried to find web.config version here is what i found
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<!-- Quitar los slash '/' del final de la ruta -->
<rule name="RewriteRequestsToPublic">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
</conditions>
<action type="Rewrite" url="/{R:0}" />
</rule>
<!-- Si el archivo o carpeta solicitado no existe, se realiza la petición a través de index.php -->
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/index.php/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
it kinda works , but it doesn't load static files (css , js ) like if i go to
site.com/public/js/jquery.js
i get this error
HTTP Error 500.52 - URL Rewrite Module Error.
The page cannot be displayed because an internal server error has occurred.
Detailed Error Information
Module RewriteModule
Notification SendResponse
Handler StaticFile
Error Code 0x800700b7
Config Error Cannot add duplicate collection entry of type 'rule' with unique key attribute 'name' set to 'Imported Rule 1'
Config File \\?\C:\HostingSpaces\phoenarts\site.com\wwwroot\public\web.config
basically it works i need to tell it to ignore link to directory and static files files
The error implies you already have a rule declared with the name Imported Rule 1 somewhere. Try changing the name of the rule in the file indicated in the error.
If you have a web.config file in ~/public and another in the web root both files are merged for requests to your static assets. This sounds like what's happening?
You can use multiple web.configs to configure different paths like this, but you shouldnt duplicate rules between them.
You can also use <location> elements in the root web.config to configure different paths (as an alternative to using multiple web.config files).

url-rewriting omitting directory from url?

Is it possible to remove a directory from URL? for example for the below urls:
http://localhost:50656/umbraco/Surface/HealthInsurance/Application?Pid=26665&Lid=73&Spid=23
http://localhost:50656/umbraco/Surface/HealthInsurance/Results/73
there need to remove umbraco/Surface/ and make it
http://localhost:50656/HealthInsurance/Application?Pid=26665&Lid=73&Spid=23
http://localhost:50656/HealthInsurance/Results/73
Please guide what will be regular expression for this.
In the web server section of your web config you can add the following. It will match the url .*, which is everything and will map it to /umbraco/Surface/{R:0}. The R:0 is the entire captured response. Make sure you have the module installed. Here is a tutorial on how to check if you have your rewrite set and you can test it. http://www.iis.net/learn/extensions/url-rewrite-module/testing-rewrite-rule-patterns
<system.webServer>
<rewrite>
<globalRules>
<rule name="MapUmbarco">
<match url=".*" />
<action type="Rewrite" url="/umbraco/Surface/{R:0}" />
</rule>
</globalRules>
</rewrite>
</system.webServer>

web.config rewrite rule in Child folder

I've a simple site with a web.config file for rewriting URL's
for instance, navigating to www.domain.com/story will show the page at www.domain.com/story.php
I've added a child folder with a copy of the site with a Chinese translation to www.domain.com/zh
I can access the story page at www.domain.com/zh/story.php but not www.domain.com/zh/story
How do I need to configure my web.config file? I've tried copying the web.config file to the /zh folder but this doesn't work, I've also tried copying and changing my match URL from ^story to ^zh/story but this also doesn't have the desired effect. Can someone suggest what is going on please?
Here is my existing web.config in the web root:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to story.php">
<match url="^story" />
<action type="Rewrite" url="story.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Haven't had a chance to try myself, but try something like this:
<rule name="Rewrite to story.php">
<match url="^zh/story" />
<action type="Rewrite" url="zh/story.php" />
</rule>

ASP.NET 4.0 Rewrite Rules in Global.aspx File Issues with rewrite

I have a rewrite rule I'm using in ASP.NET 4.0 on IIS7:
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite default to aspx" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="home.aspx" />
</rule>
</rules>
</rewrite>
<defaultDocument>
<files>
<add value="home.aspx" />
</files>
</defaultDocument>
</system.webServer>
This rule takes: (http:/example.com/aboutus.aspx) and it removes the .aspx from the end of the URL. I'm running into problems with wordpress being installed on my subdomain (http:/www.example.com/blog) I get the following error due to my rewrite rule:
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /blog/.aspx
Does anyone know how I can fix the URL rewrite rule so it safely get to (http://www.example.com/blog/) and not add the .aspx at the end?
Is there some sort of syntax that can search for the blog subdirectory to ignore the directory '/blog/'?
Greatly appreciated! Thank you! :)
If you want your rule to be applied to every urls but the /blog/* ones, then you can use the negate option:
<rule name="Rewrite default to aspx" stopProcessing="true">
<match url="^blog/" ignoreCase="false" negate="true" />
<action type="Rewrite" url="home.aspx" />
</rule>
http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#Rule_pattern_properties

Resources