Help with Friendly URL Rewrite Please :)

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 3
Joined: 08 Jun 2012, 14:06

Help with Friendly URL Rewrite Please :)

08 Jun 2012, 14:14

Here's what we need:

Friendly URL: www.client.com/title/p1/v1/p2/v2/p3/v3

Rewrite to: www.client.com/index.jsp?path=title&p1=v1&p2=v2&p3=v3 (for any number of parameters or no parameters)

This basic rule works fine for no parameters but we need with additional / separated parameters..
RewriteRule ^(.*)$ index.jsp?path=$1 [NC,L,QSA]

I've tried a couple of complex rules and to figure it out with expressions but not getting there. Any suggestions?

Thanks!!!

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

Re: Help with Friendly URL Rewrite Please :)

11 Jun 2012, 06:56

Hello,

Please, try using the following:

Code: Select all
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Rewriterule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ /index.jsp?path=$1&$2=$3&$4=$5&$6=$7


Regards
Andrew

User avatar
Posts: 3
Joined: 08 Jun 2012, 14:06

Re: Help with Friendly URL Rewrite Please :)

11 Jun 2012, 16:57

Hi Andrew,

Thanks so much for the response, unfortunately i'm not having any luck with the new Rule..

65.128.10.112 65.128.10.112 Mon, 11-Jun-2012 12:46:47 GMT [www.zzz.com/sid#2][rid#44759024/initial] (2) init rewrite engine with requested uri /to
65.128.10.112 65.128.10.112 Mon, 11-Jun-2012 12:46:47 GMT [www.zzz.com/sid#2][rid#44759024/initial] (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
65.128.10.112 65.128.10.112 Mon, 11-Jun-2012 12:46:47 GMT [www.zzz.com/sid#2][rid#44759024/initial] (3) applying pattern '^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$' to uri 'to'

65.128.10.112 65.128.10.112 Mon, 11-Jun-2012 12:46:50 GMT [www.zzz.com/sid#2][rid#44757392/initial] (2) init rewrite engine with requested uri /resources
65.128.10.112 65.128.10.112 Mon, 11-Jun-2012 12:46:50 GMT [www.zzz.com/sid#2][rid#44757392/initial] (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
65.128.10.112 65.128.10.112 Mon, 11-Jun-2012 12:46:50 GMT [www.zzz.com/sid#2][rid#44757392/initial] (3) applying pattern '^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$' to uri 'resources'
65.128.10.112 65.128.10.112 Mon, 11-Jun-2012 12:46:53 GMT [www.zzz.com/sid#2][rid#44759024/initial] (2) init rewrite engine with requested uri /about-us
65.128.10.112 65.128.10.112 Mon, 11-Jun-2012 12:46:53 GMT

It doesn't seem to be doing any translations.. i tried a few pages with and without extra parameters..

Current httpd.conf file with rules i've been trying to get to work for this...

RewriteEngine on
RewriteBase /

#Rewrite the URI if there is no file or folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# both of the following rewrite rules needed together
#RewriteRule (path=[^/]*)?/([^/]*)/([^/]*)(.*) (?1$1&$2=$3:path=$2/$3)$4 [N, NC]
#RewriteRule (path=[^/]*)/? /index.jsp?$1 [NC]

# alternate way; uses only one rewrite rule; but may cause infinite loop if trailing '/' in URL
#RewriteRule (/.*?\.jsp)?(\?path=[^/]*)?/([^/]*)/([^/]*)(.*) (?1$1:index.jsp)(?2$2&$3=$4:?path=$3/$4)$5 [R, N, NC]

# both of the following rewrite rules needed together
#RewriteRule (path=)?([^/]*)/([^/]*)/?([^/]*)(.*) (?1$1$2(?3&$3=$4:):path=$2(?3/$3/$4:))$5 [N,NC]
#RewriteRule (path=[^/]*)/? /index.jsp?$1 [NC]

# this simple rule works for the main page parameter but not with query string parameters rewritten with /
# this is currently in use to rewrite friendly urls for content pages
RewriteRule ^(.*)$ index.jsp?path=$1 [NC,L,QSA]

# helicon rule
#Rewriterule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ /index.jsp?path=$1&$2=$3&$4=$5&$6=$7

Is there a typo or something missing here?

Thanks,
Scot

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

Re: Help with Friendly URL Rewrite Please :)

12 Jun 2012, 06:36

Well,

a) you've provided logs for requests like: /to and /resources, so I can't see how it works. Please, make another attempt
b) The following conditions are NOT used for blocks of the rules, they are used in front of EACH rule that requires them:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d


Regards
Andrew

User avatar
Posts: 3
Joined: 08 Jun 2012, 14:06

Re: Help with Friendly URL Rewrite Please :)

18 Jun 2012, 15:26

Thanks for the tips! i did some more testing with this, here are the rules i set up:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !.jpg
RewriteCond %{REQUEST_FILENAME} !.gif
RewriteCond %{REQUEST_FILENAME} !.png
RewriteCond %{REQUEST_FILENAME} !.css
RewriteCond %{REQUEST_FILENAME} !.js
RewriteCond %{REQUEST_FILENAME} !.pdf
Rewriterule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ /index.jsp?path=$1&$2=$3&$4=$5&$6=$7 [L, NC]


What i found is that it works with 3 parameters such as:
www.site.com/pagetitle/p1/v1/p2/v2/p3/v3

rewrites to: www.site.com/index.jsp?path=pagetitle&p1=v1&p2=v2&p3=v3

If i send in any other number of parameters it fails.. i'll need it to work with any number of parameters from 0 to who knows.

so:
www.site.com/pagetitle should rewrite to: www.site.com/index.jsp?path=pagetitle

www.site.com/pagetitle/p1/v1/p2/v2/p3/v ... 5/v5/p6/v6 should also work to add in all parameters found...

Thanks!

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

Re: Help with Friendly URL Rewrite Please :)

19 Jun 2012, 09:14

There's no universal rule. It's better to make a new rule, based on the one you already have, that matches 2 parameters... than 1 parameter, etc.

Regards
Andrew

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 4 guests