PDA

View Full Version : Hosting Isapi_Rewrite Vesion 3 examples (Isapi Rewrite)



Brian
November 18th, 2009, 05:52 PM
Hostek.com has lots of experience with Isapi_Rewrite Hosting. Here are a couple of examples of using Isapi_Rewrite Version 3:

NOTE: Place the rewrite rules in a file named .htaccess and place it at the web root (ie, /wwwroot folder)

Redirecting non-www version to www

RewriteEngine on

RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]


Suppose you have URL like www.example.com/foo.asp?a=A&b=B&c=C and you want to access it as www.example.com/foo.asp/a/A/b/B/c/


RewriteEngine on
RewriteRule ^(.*?\.asp)/([^/]*)/([^/]*)(/.+)? $1$4?$2=$3 [NC,LP,QSA

Additional Isapi_Rewrite rules/examples can be found at the Isapi_Rewrite (http://www.helicontech.com/isapi_rewrite/doc/examples.htm#SEF) site.

AlexY
November 30th, 2009, 05:56 PM
Suppose you have URL like http://shop.example.com and you want your visitors to be redirected to https://shop.example.com

Here is example how to force SSL for certain folder. Simply put following rules into the .htaccess file in this folder:



RewriteEngine on

#Fix missing trailing slash char on folders
RewriteRule ^([^.?]+[^.?/])$ $1/ [R,L]

#Redirect non-HTTPS to HTTPS
RewriteCond %{HTTP:Host} (.*)
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (.*)
RewriteRule .? https://%1%2 [R,L]

nitewatch
December 17th, 2009, 08:33 AM
I have added the following to the .htaccess:

RewriteEngine on
RewriteRule ^(/(ajaxproxy|flex2gateway|jrunscripts|cfide|cfformga teway|railo-context|files|images|javascripts|miscellaneous|sty lesheets).*)$ $1 [L,I]
RewriteRule ^(/.+/.+/.*\?.+\..*)$ /rewrite.cfm/$1
RewriteRule ^(/[^.]*)$ /rewrite.cfm/$1

It doesn't appear to be working. Can you confirm this is correct syntax?

Thanks!

davidd
December 17th, 2009, 03:10 PM
nitewatch,

Try removing the beginning forward slash('/') in each rewrite rule. Also, I would recommend revising the first rewrite rule as it does not look correct for excluding those folders from the rewriting. Below is an example of what I would suggest:


RewriteEngine on
RewriteRule ^(ajaxproxy|flex2gateway|jrunscripts|cfide|cfformg ateway|railo-context|files|images|javascripts|miscellaneous|sty lesheets) - [L,I]
RewriteRule ^(.+/.+/.*\?.+\..*)$ /rewrite.cfm/$1
RewriteRule ^([^.]*)$ /rewrite.cfm/$1


If that does not resolve the issue, try using the test files from the following post to determine if ISAPI_Rewrite V3 is working on your site:
http://forum.hostek.com/showthread.php?t=147


If the test does not work, then submit a support ticket (https://support.hostek.com/Customer/SubmitTicket.aspx) as the post mentions, and we can check into it.(note: Be sure to include your domain name in the ticket)


If the test confirms that ISAPI_Rewrite V3 is working, then we would need to know an example of a URL that you are wanting rewritten to determine if rules 2 and 3 would actually rewrite it.

Brian
April 10th, 2010, 12:15 AM
Example on how to prevent certain spiders from crawling your site:



RewriteEngine on

RewriteCond %{HTTP_USER_AGENT} ^Baiduspider.*$
RewriteRule .* /block.htm

RewriteCond %{HTTP_USER_AGENT} ^Yandex.*$
RewriteRule .* /block.htm

Brian
May 5th, 2010, 04:58 PM
To have your index.htm page auto redirect to index.asp user this example:



RewriteEngine on

RewriteRule index.htm index.asp [I,O,R=301,L]

Brian
September 13th, 2010, 08:48 PM
Here is an example to show how to get the variables from positions 1 and 2 without it mattering how many items are in the URL. In other words, a good example for a rewrite rule for optional parameters.

Let's say you want to have a URL display like:

http://your_domain.com/some-folder/34-77-some-key-word.html

But you want that to really process a query like:

http://your_domain.com/folder/search.asp?country=34&city=77



RewriteEngine on
RewriteRule ^some-folder/([^-]+)-([^-]+)-.*$ /folder/search.asp?country=$1&city=$2

Brian
October 6th, 2010, 10:32 AM
A common use for this one is when using Mura, but you don't want the index.cfm in URL

Example: domain.com/test/test2

Would really load what would be at: domain.com/index.cfm/test/test2


RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.cfm/$1 [L]

davidd
October 27th, 2010, 01:31 PM
Rewrite all wild-card sub-domain requests to a folder without affecting "your_domain.com" or "www.your_domain.com":

Wild-Card Subdomains



# Ignore requests that are already rewritten
RewriteRule ^subdomainfolder/.*$ - [NC,L]

# Rewrite all requests to non-www sub-domains to /subdomainfolder
RewriteCond %{HTTP_HOST} !^(www\.)?your_domain\.com$ [NC]
RewriteRule ^(.*)$ /subdomainfolder/$1 [L]

acemonroe
November 2nd, 2010, 11:27 AM
How do I redirect a complete directory such as /joomlainstallation in the root as the primary page?

I have a site that is currently outdated such as example.com and have created a joomla installation inside that directory that is viewable at example.com/joomlainstallation. My goal is to direct the /joomlainstallation to example.com?

Any help?

chrisd
November 2nd, 2010, 12:26 PM
Acemonroe,
You can use code similar to the code below.

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/folder(\/)?
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.
RewriteRule ^(.*)$ folder/$1 [L]

You would replace "folder" with the name of your folder, and replace domain, with the name of your domain.

acemonroe
November 3rd, 2010, 04:07 PM
still no success doing this.

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/NewFolder(\/)?
RewriteCond %{HTTP_HOST} ^(www\.)?example.com\.
RewriteRule ^(.*)$ folder/$1 [L]

This isn't what I'm using but how I'm adding my info in. Does the bottom line where it says "folder" get renamed?
Also is there a time period before this takes effect?

davidd
November 3rd, 2010, 04:49 PM
The following should redirect all requests for your domain to the /subfolder directory. You can update 'subfolder' to whatever folder to which you are wanting the requests to go:


RewriteEngine On

# Exclude requests already going to /subfolder to avoid an infinite loop
RewriteRule ^subfolder.*$ - [NC,L]

# Rewrite normal requests to /subfolder
RewriteRule ^(.*)$ /subfolder/$1 [L]


David D.

draymondkc
January 8th, 2011, 08:36 PM
put...

RewriteEngine on
RewriteRule about.html index.cfm [I,O,R=301,L]

in .htaccess
but about.html is not redirecting. Not sure what I'm doing wrong.
thanks!

davidd
January 10th, 2011, 11:47 AM
I tested the rewrite rule you gave and it worked correctly for me on a test site.

Please submit a support ticket via our support page (https://support.hostek.com/) or by emailing [email protected] We can then test this on your site and figure out what the issue is.

chrisd
June 17th, 2011, 08:42 AM
Exclude specific files such as "css, jpg, gif" from your 301 redirect.

Exclude files from 301 redirect

**Note**
Replace "css|jpg|gif" with the file types you need to be excluded.

RewriteRule ^.+\.(?:css|jpg|gif)$ - [NC,L]

CalebC
November 6th, 2011, 08:39 AM
How to set a non-www to www redirect while not affecting your shared SSL, if you have it enabled.


RewriteEngine on
# handle non-www HTTPS redirects. Consecutive conditions are implicitly ANDed together.
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{HTTP_HOST} ^(?!www\.).*mywebsite\.com$
RedirectRule ^/(.*)$ https://secure#.ezhostingserver.com/mywebsite-com/$1 [R=301]

# All requests arriving to this point either use www for the hostname, or use
# HTTP for the protocol.

# handle non-www non-HTTPS redirects
RewriteCond %{HTTP_HOST} ^(?!www\.).*mywebsite\.com$
RedirectRule ^/(.*)$ http://www.mywebsite.com/$1 [R=301]

JonC
November 7th, 2011, 09:05 AM
Rewrite all requests for /joomlainstallation to the root level:

RewriteRule ^joomlainstallation/(.*)$ /$1 [NC,R=301]

usef4u
June 1st, 2012, 06:44 AM
Hi
Can anybody help, i am getting this error

Its giving me 400 Bad Request..
I don't know how this url came in google index, actually its joining my home page and my product page with a space in between..
like this
http://www.mywebsite.com/ http://www.mywebsite.com/10014.htm
and its giving me a 400 error

I want this to be redirected 301 to my product page like this http://www.mywebsite.com/10014.htm

Can anyone Help.

Thanks

JanetEdkins
June 6th, 2012, 07:31 AM
Guys - I'm so hoping you can assist me. I took the basic Redirecting non-www version to www as a good place to start

All I want to do after that is make old htm files redirect to the new WP pages

I tried rewrite rules both with & without the full http:// path - and as you see below tried it with just the begging forward slash /

I took the RewriteRules from the post :-

RewriteRule index.htm index.asp [I,O,R=301,L]

So below is my code and its not redirecting, any idea what I missed? Oh and I also tried adding the isapi Rewrite plugin to wp.

RewriteEngine on

RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]


RewriteRule statement2.htm /?page_id=35 [I,O,R=301,L]
RewriteRule fairs.htm ?page_id=11 [I,O,R=301,L]
RewriteRule galleries.htm ?page_id=63 [I,O,R=301,L]
RewriteRule recipes.htm ?page_id=41 [I,O,R=301,L]

davidd
June 6th, 2012, 10:43 AM
Hi
Can anybody help, i am getting this error

Its giving me 400 Bad Request..
I don't know how this url came in google index, actually its joining my home page and my product page with a space in between..
like this
http://www.mywebsite.com/ http://www.mywebsite.com/10014.htm
and its giving me a 400 error

I want this to be redirected 301 to my product page like this http://www.mywebsite.com/10014.htm

Can anyone Help.

Thanks


The following rule should perform the appropriate redirect and fix any similar urls as well:

RewriteRule http://www\.mywebsite\.com(.*)$ $1 [NC,R=301]

NOTES:
The 'NC' flag means 'No Case', making the regular expression case-insensitive.
The 'R' flag causes ISAPI_Rewrite to redirect rather than rewrite the URL internally with the option of also setting the http status code to use.

davidd
June 6th, 2012, 10:56 AM
Guys - I'm so hoping you can assist me. I took the basic Redirecting non-www version to www as a good place to start

All I want to do after that is make old htm files redirect to the new WP pages

I tried rewrite rules both with & without the full http:// path - and as you see below tried it with just the begging forward slash /

I took the RewriteRules from the post :-

RewriteRule index.htm index.asp [I,O,R=301,L]

So below is my code and its not redirecting, any idea what I missed? Oh and I also tried adding the isapi Rewrite plugin to wp.

RewriteEngine on

RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]


RewriteRule statement2.htm /?page_id=35 [I,O,R=301,L]
RewriteRule fairs.htm ?page_id=11 [I,O,R=301,L]
RewriteRule galleries.htm ?page_id=63 [I,O,R=301,L]
RewriteRule recipes.htm ?page_id=41 [I,O,R=301,L]


I tested the rewrite rules you posted, and they worked successfully on my test site. If you are on a Windows 2008 server, WordPress may have some IIS rewrite rules within the web.config file that could be interfering with ISAPI_Rewrite. I would check the contents of the web.config file if one exists to see if that may be the case. If it is, you will need to integrate all of the rewrite rules into a single file, either the .htaccess file (ISAPI_Rewrite) or the web.config (IIS Rewrite Module).


NOTE: It looks like the rules you copied were taken from some rules that had RewriteCompatibility2 turned on as many of the option flags are unnecessary. The following version is slightly more succinct:

RewriteEngine on

RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301]

RewriteRule statement2.htm /?page_id=35 [NC,R=301]
RewriteRule fairs.htm ?page_id=11 [NC,R=301]
RewriteRule galleries.htm ?page_id=63 [NC,R=301]
RewriteRule recipes.htm ?page_id=41 [NC,R=301]

JanetEdkins
June 8th, 2012, 08:29 AM
I tested the rewrite rules you posted, and they worked successfully on my test site. If you are on a Windows 2008 server, WordPress may have some IIS rewrite rules within the web.config file that could be interfering with ISAPI_Rewrite. I would check the contents of the web.config file if one exists to see if that may be the case. If it is, you will need to integrate all of the rewrite rules into a single file, either the .htaccess file (ISAPI_Rewrite) or the web.config (IIS Rewrite Module).


NOTE: It looks like the rules you copied were taken from some rules that had RewriteCompatibility2 turned on as many of the option flags are unnecessary. The following version is slightly more succinct:

RewriteEngine on

RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301]

RewriteRule statement2.htm /?page_id=35 [NC,R=301]
RewriteRule fairs.htm ?page_id=379 [NC,R=301]
RewriteRule galleries.htm ?page_id=304 [NC,R=301]
RewriteRule recipes.htm ?page_id=41 [NC,R=301]

Thanks David for the info. I updated my .htaccess but am still seeing the old pages. Does this take time to propagate on the server or should it be immediate?

Also, I noticed line one of the page redirects has a back slash and the others don't so I've tried it both ways!

chrisd
June 8th, 2012, 09:01 AM
JanetEdkins,

Please try clearing the cache within your browser to be sure that you are not accessing a cached page, clearing the cache will force the browser to regather all of the information from the server.

JanetEdkins
June 8th, 2012, 10:01 AM
Thanks Chris - should have said I'd already tried that - and I've tried other browsers that are not my regular one.

site is www.inthestixstudio.com - I am seeing it as it should be = new WP site build, but client says some of her customers are reporting they are still seeing the old site. I have now changed all the old pages to show a link to the new equivalent page but I would like the redirect to work if at all possible. Do you have any suggestions for me?

Tanks for your help. Oh and from a previous post, if I need to know, how can I find out what version of Windows Hostek are using to host this domain. Thanks again J

chrisd
June 8th, 2012, 11:58 AM
JanetEdkins

I have created a ticket for your specific issue and am replying directly to the email address on file with the information you requested as well as resolution for your customers.