Small help in url rewriting - ruby

I want to redirect all these kind of requests
http://www.example.com/2013/01/my-sample-post/feed
or
http://www.example.com/2013/01/my-sample-post/feed/
to
http://www.example.com/2013/01/my-sample-post/
I am using sinatra and rack--rewrite gem.
rewrite %r{/*/feed?}, '/$1' // not working..

You missed a dot in the regex. You also need a capture group with () around the wildcard, so it should be (.*) between the slashes. Iguess you are also missing a slash at the end. This should work:
rewrite %r{/(.*)/feed/?}, '/$1'

Related

IIS7.5 URL Rewrite, with or without trailing slash

I'm using IIS7.5 and have a rule for rewriting a URL...
The rule is:
^trade/new_products/page([^/]+)/?.*$
But, this is only working when I don't include a slash - e.g.
http://www.website.com/trade/new_products/page1
I'd like it to also work with
http://www.toppstiles.co.uk/trade/new_products/page1/
Can I do this or do I need a separate rule?
This group ([^/]+) is catching everything but slash. If your page is only numeric you can try this one:
^trade/new_products/page([0-9]+)/?.*$
If not, you can use the non greedy modifier on the multiplier(+?):
^trade/new_products/page([^/]+?)/?.*$
Sorry - the rule was working as expected - it was another issue that was causing my problem!

isapi rewrite 3 changing # character into a %23 in browser

All,
Trying to redirect too a URL like below:
http://domain/something/index.html#some/more/stuff.html
only problem here is that the # is getting changed into a %23 and it does not fine this URL.
Am i supposed to treat this differently?
Thanks in advance
Citty
Was missing the no escape tag [NE]
citty

URL rewriting with ISAPI Rewrite

I am trying to create a filter system for products and keep the URL's friendly, i am using a map file for the filter params and the following re-write code.
The url could contain, one param or 10 params and will be bulit like so
Start URL: www.domain.com/climbing-frames/
First Param: www.domain.com/climbing-frames_rockwall/
Second Param: www.domain.com/climbing frames_rockwall_rope-ladder/
And so on.....
The rewrite rule so far
RewriteMap features txt:features.txt
RewriteCond ${features:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^climbing-frames(?:_([^/]+))(?:_([^/]+))(?:_([^/]+))(?:_([^/]+))/ /get-features.cfm?(?1(param1=${features:$1|0}))(?2(,${features:$2|0}))(?3(,${features:$3|0}))(?4(,${features:$4|0}))
This works if 4 prams are entered but not if only two params are entered. This is driving me crazy!
Any clues would be greatly appreciated.
Jason
I think you're close - there might be a looping approach that would be better, but I do tend to go with the way you're going.
I see how you're doing the non-capturing underscore, then capturing the next characters. Instead of looking for not-slash, look for not-underscore. With the not-slash, it's going to grab the whole thing in the first group. That is, look for underscore-not-underscore.
Then (getting to the real fix), each section needs to be optional - the rule above is requiring the four sections. So add a ? to the end of each one, as:
RewriteRule ^climbing-frames(?:_([^_]+))(?:_([^_]+))?(?:_([^_]+))?(?:_([^_]+))?/
I left the first group required, since it practically should be there, and the RewriteCond is checking for it anyway.

How to use mod_rewrite to change this url http://outis-music.com/#url=http%3A//outis-music.com/podcast-2/?

I need to change urls like this one http://outis-music.com/#url=http%3A//outis-music.com/podcast-2/ to eliminate this part /#url=http%3A//outis-music.com
Thank you in advance!
untested code, however you are just running a regular expression search and replace on the url string.
RewriteRule (\/#url=http%3A\/\/outis\-music.com)$ [L]
good reading:
-mod_rewrite sytax
-Regex Reference

url-rewriting and rss feed (feedburner) issue

I am using below rule to read the URL like
URL:
http://www.example.com/blog/sampe-post-title/10004/
RULE:
RewriteRule (.*)/(.*)/([0-9]+)/$ $1/details.asp?mod_id=$3 [NS,I]
Everything was fine untill I discovered that links coming via feedburner are not working anymore. Because feedburner adds some extra parameter to URL for stats/tracking etc.
For example www.example.com/blog/sampe-post-title/10004/?utm_source=feedburner&utm_medium=email&utm_campaign=Feed:+somesite+(my+feed)
My rewrite URL doesn't recognizes the above URL anymore. Any idea how to deal with it?
Try adding a rule for the feedburner URLs:
RewriteRule (.*)/(.*)/([0-9]+)/\?(.*)$ $1/details.asp?mod_id=$3&$4 [NS,I]
I added an extra RegEx group at the end to capture everything after the question mark and place it after mod_id. You could probably combine this with your other URL if you only wanted to have one rule for some reason, but you might as well just have two.
Try the QSA flag to get the original requested URL query automatically appended to the new one.
I managed to figure out the answer on my own: just replace the ending $ with .* That's it!
Here is the modified rule:
RewriteRule (.*)/(.*)/([0-9]+)/.* $1/details.asp?mod_id=$3 [NS,I]

Resources