images and css are not downloading for iis url rewrite - asp.net

i am running my site from VS2013 IDE
i have include country code in url by http module like http://localhost:53741/gb/
but there is no folder called gb. so i suppose to get error. just to by pass that error i copy iis url rewrite rule in my web.config file. here it is
<rule name="Rewrite rule for Redirecting countries" stopProcessing="true">
<match url=".*" />
<conditions trackAllCaptures="true">
<add input="{REQUEST_URI}" pattern="[a-z]{2}/(.*)" />
</conditions>
<action type="Rewrite" url="/{tolower:{C:1}}" appendQueryString="false" logRewrittenUrl="true" />
</rule>
now the above url works but js and css file not downloaded. i checked with developer tool and js/css files path are ok.
my css is in content folder in root folder and js is in scripts folder. when i check the url of js and css then i found those was ok but files do not downloaded.....do not understand why?
here is developer tool screen shot
just see the file path from picture above. that is right.
i use this rule
<rule name="Some rule">
<conditions logicalGrouping="MatchAny">
<add input="{URL}" pattern="^.*\.(ashx|axd|css|gif|png|jpg|jpeg|js|flv|f4v)$" negate="true" />
</conditions>
</rule>
but still no luck.what causing problem.anyone can help me to figure out this issue. thanks

Related

IIS 10: Serve file with same name as directory

I've just set up a IIS server, and made a simple website. I have a file called "image.aspx" and a directory called "image" and I have URL Rewrite 2.0 to not need the .aspx. When I see domain.com/image i get a no permission 403, but when I visit domain.com/image.aspx it shows. How can I make it that when you visit domain.com/image you go to domain.com/image.aspx but you are able to go to domain.com/image/file.aspx?
We just check if the file with the request URL name exists then make a redirection. Moreover, the specific file under that directory is accessible too.
<rules>
<rule name="MyRules" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{DOCUMENT_ROOT}{Request_URI}.aspx" matchType="IsFile" />
</conditions>
<action type="Redirect" url="Https://vabqia969vm:448{request_URI}.aspx" />
</rule>
</rules>
</rewrite>
Feel free to let me know if the problem still exists.

Using IIS Rewrite URL for SEO to move all Cold Fusion CFM pages to ASP aspx pages

I am moving a large database driven website from coldfusion .cfm to .net aspx. I am pretty much finished now, but I need to do 301 redirects on all the coldfusion pages to the new aspx ones, so google and such like as we don't want to lose the search engine positioning. So I intended to use URL Rewrite for this, but I cannot get it working, most of the time I just get 404s back.
Basically, my new aspx pages are all the same filename, just .cfm is replaced with .aspx, some pages can have a long querystring after them and some not.
Examples:
http://www.example.com/test.cfm needs to be remapped to http://www.example.com/test.aspx
http://www.example.com/test2.cfm?a=1&b=2&c=3 needs to be remapped to http://www.example.com/test2.aspx?a=1&b=2&c=3
The site itself has hundreds of pages and some pages have over 8 variables in the querystring, so I just wanted to try and do a straight map over in URL rewrite. I cannot do a rule per page as that will take ages!
My current attempt is:
<rule name="redirect all requests" stopProcessing="true">
<match url="^(.*)$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll">
<add input="{URL}" pattern="^http://www.example.com/(.*).cfm(.*)$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{C:1}.aspx" appendQueryString="true" logRewrittenUrl="true" />
</rule>
This just does a 404 for me. Obviously the cfm pages do not exist and the aspx ones now do. I still have cold fusion installed on the server for now, and do not want to uninstall it until google has updated itself (it case of issues so I can always go back).
Any help would be much appreciated.
Thanks
David
It's like this...
<rule name="CFM301ASP" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" pattern="^.*\.cfm$" negate="false" ignoreCase="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
</conditions>
<action type="Redirect" url="/yourfile.aspx" appendQueryString="true" redirectType="Permanent" />
</rule>
This only works on CFMs that do not exist (isFile=false). It will 301 redirect CFMs that would cause a 404, to your ASP file, and append the URL variables.
The documentation seems to cover all of this.
From the docs on HTTP Redirect:
<configuration>
<system.webServer>
<httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found">
<add wildcard="*.php" destination="/default.htm" />
</httpRedirect>
</system.webServer>
</configuration>
This led me to believe that you should be able to map URLs from one file extenstion to another.
Creating Rewrite Rules for the URL Rewrite Module
<rewrite>
<rules>
<rule name="Rewrite to article.aspx">
<match url="^article/([0-9]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="article.aspx?id={R:1}&title={R:2}" />
</rule>
</rules>
</rewrite>
Try reading through these docs, you should be able to find the correct syntax that will allow you to just transfer from *.cfm to *.aspx, passing along the same query strings, or making translations as needed.

W3 Total Cache IIS minify error

My Problem
I am getting an error trying to minify URLs using the Wordpress plugin W3 Total Cache with IIS.
W3 Total Cache error:It appears Minify URL rewriting is not working.
Please verify that the server configuration allows .htaccess
Unfortunately minification will not function without custom rewrite
rules. Please ask your server administrator for assistance. Also refer
to the install page for the rules for your server. Technical info
.htaccess file contains rules to rewrite url
http://myurl.com/:\Web\Public_Test2/wp-content/cache/minify/000000/w3tc_rewrite_test.
If handled by plugin, it returns "OK" message. The plugin made a
request to
http://myurl.com/:\Web\Public_Test2/wp-content/cache/minify/000000/w3tc_rewrite_test
but received: Connection timed out after 2016 milliseconds instead of
"OK" response.
(note: I edited the domain name for privacy) I find the URL to be quite odd having the domain in there but I do not know how to change the default URL it tests. If coming from the main directory it is indeed Web/Public_Test2/wp-content/cache/minify but there is no 000000 folder in there.
W3 Total Cache Recommendations
Under the install tab for the plugin there is a note for people not using apache:
In the case where Apache is not used, the .htaccess file located in the root directory of the WordPress installation, wp-content/w3tc/pgcache/.htaccess and wp-content/w3tc/min/.htaccess contain directives that must be manually created for your web server software.
However, a w3tc folder does not exist, only a w3tc-config folder which has a master.php and master-admin.php file, no .htaccess or subfolders. I checked a cache folder under wp-config and there is no .htaccess in any subfolder. So I am not sure how to change the web.config or with what directives.
My Attempt
I found somewhere suggesting that these rewrite rules be added to web.config, I added them but it did not change the error at all:
<rule name="w3tc_rewrite_test" stopProcessing="true">
<match url="^wp-content/cache/minify/000000/w3tc_rewrite_test" />
<action type="Rewrite" url="wp-content/plugins/w3-total-cache/pub/minify.php?w3tc_rewrite_test=1" logRewrittenUrl="true" />
</rule>
<rule name="w3tc-minify-test-file" stopProcessing="true">
<match url="wp-content/cache/minify/(.+/[X]+\.css)$" />
<action type="Rewrite" url="wp-content/plugins/w3-total-cache/pub/minify.php?test_file={R:1}" />
</rule>
<rule name="w3tc-minify-file" stopProcessing="true">
<match url="wp-content/cache/minify/(.+\.(css|js))$" />
<action type="Rewrite" url="wp-content/plugins/w3-total-cache/pub/minify.php?file={R:1}" />
</rule>
I ran into the same issue and here is the solution that worked for me:
W3 Total Cache: Version 0.9.4.1
Wordpress: Version 4.5.2
IIS: Version 7.5
Server: Windows 2008 R2
My web.config has these rules:
<rewrite>
<rules>
<clear />
<rule name="w3tc-minify-file" stopProcessing="true">
<match url="wp-content/cache/minify/(.+\.(css|js))$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="wp-content/plugins/w3-total-cache/pub/minify.php?file={R:1}" />
</rule>
<rule name="wordpress" enabled="true" patternSyntax="Wildcard">
<match url="*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
When I put the w3tc-minify-file rule under my wordpress rule, it did not work and I was getting 404 errors on all of the minify files W3TC was creating.
I'm using manual mode minify and just combining my css and js files and it's working great. Hope it helps someone.
The chances of this working with the auto minify mode are very low, so I definitely recommend doing the manual mode for the highest chance of success. I had 3 JS files and 2 CSS files I could not combine/minify because they broke my site. Manual mode gives you the most control, so spend a bit of time adding each file until you have it as best as you can.

Stopping hotlinking from a directory using web.config

I have a folder on my site for caching large flash movies and I want to stop other people from embedding them in their site; I would like to try and do this using the web.config file only. How could this be done?
My first attempt at a rule (which doesn't work):
The following rule was supposed to prevent public access (and embedding) to .swf files in the cache folder 'CurrentCache' - http://myurl.com/ContentCache/ and give a replacement movie 'NoEmbedFromCacheSWF.swf' instead.
<rule name="Prevent SWF hotlinking" enabled="true">
<match url="^(ContentCache)(.swf)$" ignoreCase="true" />
<conditions>
<add input="{HTTP_REFERER}" pattern="^http://(.*\.)?myurl\.com/.*$" negate="true" />
</conditions>
<action type="Rewrite" url="/Content/Flash/NoEmbedFromCacheSWF.swf" />
</rule>
Thanks in advance!
Note: I think I have got the regex wrong in the <match url="A swf inside /ContentCache/" ignoreCase="true" /> line, any ideas what it should?
You can build an HttpModule for this. There is a blog posting describing exactly what you want to do I think:
HttpModule to block external referrers in ASP.NET
Edit: Of course I'm bending the rules here about web.config only. You have to use an external module, but then you can use it referencing from web.config only without modifying any of your code.
Edit2: If you want to do it using a rewrite rule, you have to change your pattern, like this:
<rule name="Prevent SWF hotlinking" enabled="true">
<match url="/ContentCache/.*\.swf$" ignoreCase="true" />
<conditions>
<add input="{HTTP_REFERER}" pattern="^http://(.*\.)?myurl\.com/.*$" negate="true" />
</conditions>
<action type="Rewrite" url="/Content/Flash/NoEmbedFromCacheSWF.swf" />
</rule>
The pattern used is a regular expression, you can read up on them here and you can test them for example on this webpage.

Wordpress permalinks on IIS?

I am using WordPress on Windows 7 IIS to develop. I am uploading images in WordPress for a blog post. The image displays fine on the web site but as soon as I enable permalinks the images no longer work and any future images uploaded I get back an error:
HTTP Error 500.50 - URL Rewrite Module Error.
The page cannot be displayed because an internal server error has occurred.
I am not sure why this would be happening, here is my web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="wordpress" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
As soon as I turn off my permalinks and use the default it works, does anyone know why this could be?
The image issue was a permission issue, but simply setting it manually
on the original image file or parent folder is inadequate. The
behavior of WordPress is that it writes the original file using IUSR
to a temporary system directory that is defined in the PHP.ini file.
This temp folder does not have IIS_IUSRS permissions on it, so when
windows moves this file from the temp folder to the application's
upload folder, its final home, IIS_IUSRS only has read permissions, so
the permissions are not inherited from the file's parent folder.
To fix this, there are two solutions.
Change the permissions on the temp folder giving IIS_IUSRS write/modify.
Change the path of the temp folder in the PHP.ini file to a folder that does have IIS_IUSRS write/modify permission.
Here is a good source detailing the problem:
http://www.howyoudo.info/index.php/how-to-fix-windows-server-upload-file-inherit-permissions-error/
I chose to move the temp folder in my PHP.ini to
C:\inetpub\temp\uploads and also give it permissions. After uploading
an image in wp-admin, I was able to access the image (original, not
resized) from a browser wihout the 500.50 error.
From source
There's a slightly different web.config at Using Permalinks « WordPress Codex as well as other options for Permalinks without mod rewrite on Windows.
To help other users this issue is due to permissions in IIS and a fix is also here:
http://forums.iis.net/t/1159252.aspx
use this below mention RULEs in your web.config file ..
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^index\.php$" ignoreCase="false"/>
<action type="None"/>
</rule>
<rule name="Redirect Image to HTTP" stopProcessing="true">
<match url=".*\.(gif|jpg|jpeg|png|css|js)$" ignoreCase="true"/>
<action type="Rewrite" url="{R:0}"/>
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="." ignoreCase="false"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true"/>
</conditions>
<action type="Rewrite" url="/index.php"/>
</rule>

Resources