Help with simple Query String

Topics: Developer Forum, User Forum
Apr 16, 2007 at 8:56 AM
I cannot put my head around this. I simply want to convert this...

www.mydomain.com/portfilio/119

into this...

www.mydomain.com/portfolio.aspx?clientID=119


I have had some luck with the rewrite below. I can at least access the page using just "mydomain.com/portfolio/119" which is very cool, but the query string isn't getting passed to the page and all of my relative images on the page now have "/portfolio" in the links. I would appreciate any help.

RewriteRule ^/portfolio/...$ /portfolio.aspx?clientID=$1


Thanks,

Brian

Apr 16, 2007 at 11:28 AM
Okay, this ended up working for me...

RewriteRule ^/portfolio/(\d+) /portfolio.aspx?clientID=$1 I,L

Although, I decided to forgo the path change so that my image, css links wouldn't be broken and I would have to change all of the links relative to the root manually. So, now I am using...

RewriteRule ^/(\d+) /portfolio.aspx?clientID=$1 I,L

This was probably as easy as it gets for rewriting, yet it took me hours to figure this out. Very powerful, but difficult for simple minds to grasp. :)

Apr 16, 2007 at 12:01 PM
You typically should keep all internal links (images, css, script links) relative to the root of your site - it's easier to manage and reduces all the extra requests for those resources.

This way you can make more meaningful friendly URLs as you initially posted.

You could also have written the initial rule such as

RewriteRule ^/portfolio/(0-9+)$ /portfolio.aspx?clientID=$1 I,L

Don't forget the "$" as that signifies the end of the expression.

Apr 16, 2007 at 8:15 PM
I appreciate the advice. You make a very good point. Keeping "Portfolio/123" makes the URL more descriptive and just makes more sense. I have updated my site already and it works great. Thanks!
May 1, 2008 at 8:31 AM
Hi,
I tried the same as above. However I am getting the following error in my Log file. Check the warning which reads badly formed RewriteRule.

All I want is, say for e.g. http://mydomain.com/documents/111/yyy/eee/iii to be redirected to http://mydomain.com/x.asp?QS=111/yyy/eee/iii

Is there any way by which I can achieve it?

Cheers





--------------------------------------------
Thu May 01 09:24:00 2008 - Read .ini file: setting LogLevel to 3
Thu May 01 09:24:00 2008 - Read .ini file: Filter Priority is now: HIGH (0x80000)
Thu May 01 09:24:00 2008 - ini line 4: RewriteRule 1 ^/documents/(0-9+)$ /Test.asp?QS=$1 I,L
Thu May 01 09:24:00 2008 - ParseRuleModifierFlags: 'I,L'
Thu May 01 09:24:00 2008 - WARNING: Badly formed RewriteRule modifier flags.
Thu May 01 09:24:00 2008 - Done reading .ini file: Found 1 rules (0 failed) on 5 lines
Thu May 01 09:24:00 2008 - Ionic URL Rewriting ISAPI Filter v1.2.12c
Thu May 01 09:24:00 2008 - Initialize, main threadId= 5376
Thu May 01 09:24:00 2008 - File watcher thread created.
Thu May 01 09:24:00 2008 - GetFilterVersion
Thu May 01 09:24:01 2008 - DllMain THREAD_DETACH, threadId= 3280
Thu May 01 09:24:01 2008 - DllMain THREAD_DETACH, threadId= 2224
Thu May 01 09:24:01 2008 - DllMain THREAD_DETACH, threadId= 4644
Thu May 01 09:24:01 2008 - DllMain THREAD_DETACH, threadId= 5284
Thu May 01 09:24:31 2008 - HttpFilterProc SFNOTIFYURL_MAP
Thu May 01 09:24:31 2008 - HttpFilterProc SFNOTIFYAUTH_COMPLETE
Thu May 01 09:24:31 2008 - DoRewrites
Thu May 01 09:24:31 2008 - New Url: '/Enquiry_WebSite/documents/115'
Thu May 01 09:24:31 2008 - ApplyRules (depth=0)
Thu May 01 09:24:31 2008 - Rule 1 : -1 (No match)
Thu May 01 09:24:31 2008 - ApplyRules: returning 0
Thu May 01 09:24:31 2008 - No Rewrite
May 6, 2008 at 9:53 AM
Got this working with a little bit of research.
However, when the Rewrite rule is redirecting to the desired page, I don't want the URL in the browser's address control to actually reflect the redirected URL instead it should reflect the original URL typed by the user.

Is there any setting in the RewriteRule command to achieve this?

Cheers
Coordinator
May 31, 2008 at 10:00 PM
Are you using the [R] flag?
That is a redirect.

If not, then the browser window should not show any change in the URL.  Rewriting URLs is done strictly on the server.