Rewrite Rule Config... Is this possible? - iis-7

So I have a set of pages like so:
domain.com/product/?_d=1
domain.com/product/?_d=2
domain.com/product/?_d=3
I have set up a rewrite map for cleaner URLs like so
domain.com/shoes
domain.com/pants
domain.com/gloves
So now I have nice URLs for people. But what I also want to do is start forwarding the existing URLs to the newer URLs. So for anyone who goes to:
domain.com/product/?_d=1
I want them to be forwarded or rewrite the URL to:
domain.com/shoes
I tried adding in another map where I have the following:
Original: domain.com/product/?_d=1
New Value: domain.com/shoes
And I got a 404. I guess I understand why because the other map won't apply since I am using the first map. But how can I set up a map for the old URLs? Or can I? I know if my query string value was like _d=shoes I could just do a rewrite rule, but it's not like that. I guess I could change my page to be that way, but was just looking for another way.

I ended up creating a rewrite rule that looked for the pattern to the old URLs and forwarded them to the new URL. Then in my Server side code I just did a check for those legacy variables and redirected with a 301 accordingly.

Related

Regex for fixing URL patterns

I have the following url structure:
http://www.xyxyxyxyx.com/ShowProduct.aspx?ID=334
http://www.xyxyxyxyx.com/ShowProduct.aspx?ID=1094
and so on..
Recently I used IIS rewrite to rewrite this structure as
http://www.xyxyxyxyx.com/productcategory/334/my-product-url
http://www.xyxyxyxyx.com/productcategory/1094/some-other-product-url
and so on..
This works fine.
I want to create another rule so that if an invalid url requests comes with the following structure:
http://www.xyxyxyxyx.com/productcategory/ShowProduct.aspx?ID=334
the 'productcategory' part should be removed from the url and the url should look like
http://www.xyxyxyxyx.com/ShowProduct.aspx?ID=334
How do I write this rule?
It may vary depending on what you are using to apply the regex, but here's a basic one:
's|productcatgory/||'
If you want to make sure it also only does this when the xyxyxyxyx url is present, this should work:
's|^http://www\.xyxyxyxyx\.com/productcategory/|http://www\.xyxyxyxyx\.com/|'
Edit: Ah, so if productcategory could be any category, then you'll need to match around it, like so:
's|^http://www\.xyxyxyxyx\.com/.*/ShowProduct|http://www\.xyxyxyxyx\.com/ShowProduct|'

Rewrite rule with nginx replace get variable with slach

I've been reading everything i could find for two days now but nothing seems to work
I have an url like this
http://www.mysite.com/auction.php?category=23140
and want make a rewrite rule so it will appears like that
http://www.mysite.com/auction/category/23140.php
I do that only in order to build seo friendly url but so far nothing have worked.
rewrite ^/auction.php?category=(.*)$ /auction/category/$1 last;
It look so simple i realy don't know why it doesn't work.
Should i put this line in the server block or the location block ? Is the regex wrong ?
Any help will be greatly appreciated
At first, pls remember rewrite in nginx does not match query string, only uri.
For example, in this url: "/auction.php?category=23140", uri is /auction.php and query string is category=23140
So in your case, the correct rule should be:
if ( $request_uri ~ "^/auction\.php\?category=[0-9]+(.*)?$" ) {
rewrite "^.*$" /auction/category/$arg_category break;
}
Above is just a example, you can change it according to your case. And also you can find the usage of $request_uri and $arg_PARAMETER from the nginx manual.
You're doing it backwards, try this.
rewrite ^/auction/([^/]*)/([0-9]*) /auction.php?$1=$2
piece of advice, if this is a custom application you're writing without a framework, you could find a routing module that you could use and it would help you do every thing easily.

site url change by htaccess

this is my project site http://readysolution.info/usjobs/test-category/?cpid=2&c_id=acc/
i just needed show url by http://readysolution.info/usjobs/XXXX/YYYY/VVVVV instead of this
test-category/?cpid=2&c_id=acc/
this is possible by .htaccess that my site url will be show by this new format . whetver will be display after /usjobs , it will be replace another word
example : 1) if it have /usjobs/test-category/?cpid=2&c_id=acc/ , then it will be usjobs/XXXX/YYYY/VVVVV
2) 1) if it have /usjobs/test-category/?cpid=2 , then it will be usjobs/DDDD/KKKKK
please helpl me !!!!
You can use an htaccess Rewrite to "translate" a requesting URI into a WP URI. For example:
Request in the browser: mysite.com/seg_1/wp_post_slug/seg_2
With a Rewrite you can ask for mysite/com/wp_post_slug and you'll be fine.
Please note:
1) The above is pseudo code for reference purposes and might not be accurate.
2) Somewhere in the requesting RI you're going to have to have something that can be used to identify the page / post you actually want requested. For example you can't have a request of mysite.com/xxx/yyy/zzz and then somehow have a rewrite serve you mysite.com/bbb. The bbb has to be in the request so you can use the rewrite to parse it out. (Note: Actually, tere probably is a work around for this but then you're going to have to maintain some sort of reference / conversion table.)

IIS 7 URL rewrite on WCF Service

Question Edited for better understanding:
I have a WCF service and any of my links look like :
https://192.168.1.31/ContactLibrary2.0HTTPS/Service.svc/..... .
I want to get rid of the Service.svc. I installed URL Writer in IIS but i don't know how to work with it. I search a little bit and didn't find anything to help me with this particular problem.
Any idea ?
Assuming you are configuring the application hosted at /ContactLibrary2.0HTTPS directly (and not the website containing that directory, for example), you may add an exact match for:
rest/GetContact
with a rewrite url of:
Service.svc/rest/GetContact
Perhaps you wish to rewrite every action of Service.svc, however; then you would need a regular expression match for:
^rest/.*$
with a rewrite url of:
Service.svc/{R:0}
UPDATE
Assuming you also need to remove that string from the urls of your HTML pages, you would need to couple the aforementioned inbound rule with a new outbound rule, applied to the files you are interested in.
To do that, please:
add a new outbound rule to your website and give it a name;
add a new precondition with two rules (matching any of them):
{RESPONSE_CONTENT_TYPE} matches text/html
{RESPONSE_CONTENT_TYPE} matches application/xhtml+xmll
configure the rule to match the response scope, matching the content within A tags:
should match the pattern using a regular expression;
with this pattern: ^(.*)(/Service\.svc/)(.*)$
case insensitive;
configure the action to be a rewrite, with this value: {R:1}{R:3}

Rewrite Rule in Nginx

I conisder moving to Nginx but I want you to ask if is possible to rewrite urls into that schema, and if you could help me a bit:
A url like http://example.com/username into profile.php?u=username. But then, will I have problems in accessing other pages like e.g. home.php
A url like http://example.php/questions/102039/that-question into questions.php?quid=102039
Thank you very much!
Yes, it is possible to rewrite URLs with Nginx.
Your first example can be handled easily by wrapping the rewrite with a block which checks if a file (home.php in your example) exists; if it doesn't, then it tries the redirect into the profile.php request. (See the try_files syntax for this.)
Your second example is just as simple:
Rewrite ^/questions/(\d+) /questions.php?quid=$1
(Because the matching expression is not anchored at the end, it should accept any string after the digits, but I haven't checked that so I'd recommend you test it.)

Resources