Anybody interested in writing me a rewrite for querystrings?

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 2
Joined: 28 Mar 2013, 13:06

Anybody interested in writing me a rewrite for querystrings?

28 Mar 2013, 13:13

Hey,

I've had ISAPI Rewrite 3 for a while now, but can't grasp the rewrite language. Hoping you wizzes at it can help me out. I have an index page that will control the direction of what items from the database to display, based on the "directory" and "page" querystrings. Anybody know what I would need to put into the .htaccess file for the scenario below? When I test it and see that it works I'll respond with it's success so others may be able to reference off it for their use to...I REALLY appreciate it!!

Original URL:
www.domainname.com/index.asp?directory=this-is-a-test-directory&page=this-is-the-page-name

ISAPI Rewrite URL:
www.domainname.com/this-is-a-test-directory/this-is-the-page-name

Alternate Possibility:
www.domainname.com/index.asp?directory=0&page=this-is-the-page-name

Rewrite To (taking the "directory" querystring out of the rewritten URL):
www.domainname.com/this-is-the-page-name

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Anybody interested in writing me a rewrite for querystri

29 Mar 2013, 00:35

Hello,

Let try using the following code:

Code: Select all
RewriteEngine on
RewriteBase /

# rewrite for filename
RewriteCond %{HTTP:Host} ^domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /index.asp?directory=0&page=$1 [NC,L]

# rewrite for directoryname and filename
RewriteCond %{HTTP:Host} ^domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ /index.asp?directory=$1&page=$2 [NC,L]

# redirect for filename only
RewriteCond %{HTTP:Host} ^domain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^directory=0&page=([^&]+)$ [NC]
RewriteRule ^index\.asp$ /$1? [NC,R=301,L]

# redirect for filename and directroyname
RewriteCond %{HTTP:Host} ^domain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^directory=([^&]+)&page=([^&]+)$ [NC]
RewriteRule ^index\.asp$ /$1/$2? [NC,R=301,L]


The order is important.

Regards
Andrew

User avatar
Posts: 2
Joined: 28 Mar 2013, 13:06

Re: Anybody interested in writing me a rewrite for querystri

29 Mar 2013, 15:29

Andrew,

Thanks a ton for writing this. I assume I should replace the ^domain\.com$ with the actual domain name, correct? In doing that, it performed the rewrite attempt, but didn't put the querystring values in between the slashes. It wrote it like:

http://www.domain.com//

It should have wrote it like:

http://www.domain.com/this-is-a-test-directory/this-is-the-page-name

Is there another step that I need to do, or does that give you an idea of what part of the code needs to be adjusted? I appreciate your help on this.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Anybody interested in writing me a rewrite for querystri

29 Mar 2013, 20:13

Lets take a look at your rewrite.log for a testing request.
Logging issues are described at FAQ - http://www.helicontech.com/forum/10648-FAQ.html


Regards
Andrew

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 11 guests