RewriteRule: /?page=Target&q=1&id=b9dc586 - mod-rewrite

Having a hard time matching this pattern. The URL has only a query string, there is no web page specified.
Here is the URL to be rewritten:
http://foo.com/?page=Target&q=1&id=b9dc586
This is the URL it should be rewritten too:
http://foo.com/target.php&q=1&id=b9dc586
Thanks in advance,
George

Have you tried something like this?
RewriteRule ^?page=Target&q=([0-9]*)&id=([a-f0-9]*) target.php&q=$1&id=$2
Anyway I think the first '&' in your target URL should be a '?', in that case change the rule in
RewriteRule ^?page=Target&q=([0-9]*)&id=([a-f0-9]*) target.php?q=$1&id=$2

Related

Apache URL rewrite trick to fix encoded "http://"

I've some leading to a site that end up poorly formated like:
http://www.mydomain.com/directory/http%3A%2F%2Fwww.another.com%2Falink-that-doesnt-work
I would like a rewrite rule to truncate that part until the url and fix the encoding to redirect to
http://www.another.com/alink-that-doesnt-work
Thanks
Extract the hostname and link from the URL using a regular expression and used back references to substitute and redirect. Note that patterns are matched against decoded URLs.
RewriteEngine On
RewriteRule /directory/http://([^/]*)/(.*) http://$1/$2 [R]

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

mod_rewrite: Why does apache URL-encode %{HTTP_COOKIE}?

I am trying to match a value in a cookie. The problem is, Apache makes the value url-encoded. So, if I do this:
RewriteCond %{HTTP_COOKIE} ^(.+)$ [NC]
It will capture this:
session%3DeXnR1oDL1Reb8Z3Gdgk7Sg%26account%3D2%3B
instead of this:
session=eXnR1oDL1Reb8Z3Gdgk7Sg&account=2
So there is no way to get the account number to do this:
RewriteRule ^$ /accounts/%1/ [R=301,L]
Please help! I have looked everywhere on Google and stackoverflow and no one has addressed this issue. Thank you so much.
I never did find the answer -- BUT, I did find a work-around. For those having the same problem, here it is:
Separate your sub-cookie values using a character that will NOT get URL encoded. I used the dash character "-". e.g. "VAL1--VAL2".
Good luck!
Did you try using flag -> NE|noescape ?
By default, special characters, such as & and ?, for example, will be converted to their hexcode equivalent. Using the [NE] flag prevents that from happening.
RewriteRule ^/anchor/(.+) /bigpage.html#$1 [NE,R]
The above example will redirect /anchor/xyz to /bigpage.html#xyz. Omitting the [NE] will result in the # being converted to its hexcode equivalent, %23, which will then result in a 404 Not Found error condition.
Source: http://httpd.apache.org/docs/2.3/rewrite/flags.html

Mod_rewrite help

I'm trying to remove query strings from my calendar, but my mod_rewrite is not appending the query string.
The website is http://cacrochester.com/Calendar
and if you click the link to go to a different month, the query string is usually http://cacrochester.com/Calendar?currentmonth=2010-11
With my rule below, it just doesn't append the query string so when you click the next month link, it just stays on the month October. What's wrong with my rule?
Here is my rule
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^.*$ http://cacrochester.com/Calendar? [NC,R=301,L]
EDIT:
What i want is to take a url like http://cacrochester.com/Calendar?currentmonth=2010-11 and turn it into something like http://cacrochester.com/Calendar/2010-11
You probably need your app to output relative urls like "/Calendar/2010-11". That's a simple code change.
Then in Apache you'd want to rewrite those urls, using:
RewriteRule ^/Calendar/([0-9]+-[0-9]{2})$ /Calendar.php?currentmonth=$1 [NC,QSA,L]
(You don't want a RewriteCond for this rule.)
Forcing a redirect with R=301 will only expose the internal url scheme. I don't think that's what you want.
To maintain query strings when rewriting, use the QSA (query string append) flag.
[NC,R=301,QSA,L]

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