How to rewrite a URL without leaving the current page in C #?

I want to rewrite my URL without leaving the current one. I find a large number of messages related to re-writing the URL, but I have not succeeded.

I want the user to enter this url -

http://localhost:16185/Company/CareerWebsite.aspx?org_name=hire-people 

URL is automatically converted to this format -

 http://localhost:16185/hire-people 

but the original page ( Company/CareerWebsite.aspx?org_name=hire-people ) does not disappear.

This means that the user did not see the source URL ( Company/CareerWebsite.aspx?org_name=hire-people ) in the browser. The user can only see the virtual URL, for example /hire-people .

Thanks for the help...!!!

+4
source share
1 answer

Well, if you want to do it the same way as described, you need to do Redirect 301 or 302 . To rewrite links, you probably need to install the urlRewrite module for iis. So far, you need some kind of following url-rewrite rule in the web.config file:

 <rule name="RedirectUserFriendlyURL1" stopProcessing="true"> <match url="^Company/CareerWebsite\.aspx$" /> <conditions> <add input="{QUERY_STRING}" pattern="^org_name=([^=&amp;]+)$" /> </conditions> <action type="Redirect" url="{C:1}" appendQueryString="false" /> </rule> 
0
source

Source: https://habr.com/ru/post/1495897/


All Articles