Url rewriting in asp.net web forms (with some complications) - webforms

When it comes to URL Rewriting there are some alternatives these days like the IIS7 module or Urlrewriter.NET. However, as far as I can see those two are based on wildcards which I sadly cannot use.
My problem is that the data I'm working with have no real structure. A made up example:
Something.aspx?page=4 might be /Weapons/Flails/
Something.aspx=page=5 might be /Clothes/Dresses/Blue/
i.e. there is no clear match between page id and what kind of page it is pointing to. I guess this requires some kind of lookup (slugs?) in a db.
How would I implement this in the easiest way? Does any of the existing alternatives offer a solution to this or do I have to build my own module?
Thank you.

IIS7 had a regular Expression option not just wild card it also has Rewrite maps. which i think is what you are looking for, it could be your look up table.
when you set up a rewrite rule, use the drop down to find the regEx option.
also when you create the rule, the option for the map is there.

You can also use the Managed Fusion URL Rewriter and Reverse Proxy. It support the Apache mod_rewrite sytnax of configuring rewriting. And you can use this method described on my blog to create a module that can do a database lookup of these old ID's and redirect them to the correct location.
http://www.coderjournal.com/2008/12/creating-extension-module-net-url-rewriter-reverse-proxy/
Please contact me through my blog if you would like help setting up this type of rewriting.

Related

How to remove date created in blog post url for pyrocms (codeigniter)

This may or may not have been answered. Since i've been searching for a correct answer the last few days, i'm afraid not. I'm working on this project in codeigniter (pyrocms) and i'm trying to get clean urls. I already managed to remove /index.php/ from the url. Except the blog module builds the urls from the date the post have been created (www.sitename.com/year/month/post-title. Obviously i want to achieve a url like www.sitename.com/post-title.
I tried routing in the module/blog/config/routes.php but that dind't work out for me as well.
Any help in the right direction would be much appreciated.
Thanks in advance!
Assuming you're using PyroCMS v2x
www.sitename.com/post-title is going to be controlled by your pages controller. It's a special thing the core dev team wrote in.
The blog is a module so www.sitename.com/module_name/... is how you call the module.
You can shorten the URL for the blog by editing the routing control in the blog module.
You could, at best, get away with www.sitename.com/blog/title, but you'll need to rewrite some of the module code and routing to do that. There's no easy way to do it like you might find in wordpress.

iis7 redirect from url without query strings to url with query strings

My web programmer is having a hard time accomplishing a request. My guess is I'm not framing the question correctly since I'm not a programmer.
What I know about our website configuration:
The site is running on windows server 2008 IIS 7.5 using ASP.
what I don't know: I don't know if URL rewrite extension is installed.
What I'm trying to do:
vanitysub.domain.com will point to actualsub.domain.com with query string variables for Google Analytics campaign tagging appended to actualsub.domain.com
The programmer was not able to do this. I received an email with the following. "I think it has to do with the aliases I’m trying to redirect. They are both bound to the same site."
Potentially useful information:
Currently if you type in the vanitysub.domain.com it renders the correct site but the URL stays vanitysub.domain.com.
Side note: This is a Google analytics issue as well because our site has over 15 different subdomains so I have configured GA to prepend the sub.domain.com to the URI. With the current scenario this generates two separate lines in my pageview report. One for vanitysub and one for actual sub.
Can someone help me provide instruction for how to achieve "what I'm trying to do" both without the rewrite extension and with it? The programmer does not have time to research it. I'm not a programmer but know enough to know I can be dangerous(i.e. it can be done) so I need your help.
Thank you!
We were able to follow the steps outlined in a similar post with some modifications since this was only one domain and the tagging was fixed. IIS7 URL Rewrite multiple domains to a single domain including google analytics referral code

How to manage URLs in CodeIgniter so they can be updated in a single place

I believe Smarty templates has functionality built in that allows you to manage your site URLs from a config file so if something gets moved, you only have to update the URL in one place. Does this sort of functionality exist in CodeIgniter? If not, any pointers or examples on how/where to add it?
For example:
Instead of hard-coding the link it would be: Settings
But where would you want to set $links so that it was available everywhere? Or is it really best to just hard code them?
Take a look at the config class. It allows you to make custom config files.
It's not entirely made for URL's but you sure can use them.
The base url should be basically right at the start of /app/config/config.php, where app is the name of your codeigniter application folder. You access it through calls to the base_url() function.
Yes, it's called Routes, configuration located at config/routes.php. Documentation
If you ask about the rendered html of the links, then your best bet would be using site_url() in conjunction with constants, for example site_url(URL_SETTINGS);, there is no built in functionality for that, but I can say I don't think that is necessary as it would be used too rarely, but it would influence performance every single load.

How do I create a changing image for my website?

Not long ago I came across this website: http://www.danasoft.com/
This websites provides dynamically updating signatures which are pretty cool in my opinion.
There is just one thing that I don't get and would really like to know how to do.
Here's a direct link to an image on the website: http://www.danasoft.com/vipersig.jpg Try refreshing. Notice it changes? How do I achieve that? How do I have a direct link to a file like www.mypage.com/thing.jpeg output different images each time?
Basically, the URL is not actually retrieving the file directly each time, but rather the server is intercepting that URL and serving a (possibly random) image from a larger set of images. Depending on whether the server is running Apache, IIS, etc, the implementation could vary... This could also probably be achieved with the MVC routing engine by defining a custom route handler for URLs ending in '.jpg', but I'm not actually sure.
EDIT:
See this discussion for more detail on the MVC implementation.

Where do you think is best to put URL rewriting?

I am a total noob on this issue, and I wonder if I have to do that where I put the code :
In the virtual host / apache conf file ?
In a httaccess file ?
Redirect all URLs to a single entry point and parse it with a scripting language ?
What are the pro and cons ?
I'd tend to go with the .htaccess because it's easier to maintain as part of a project's files, doesn't require kicking the web server to take effect, and will typically be faster than scripting-level rewrites.
This depends on what exactly you want to do.
Rewriting rules should go in the configuration relating to the directory/site root which is typically your vhost configuration or htaccess (depending on setup).
Doing this through a script only makes sense if your redirect is based on extra information such as matching a 404 to a database of recently moved pages or a 404-URI to a search of some kind.
OK, so I put some summary of what I read on SO about it :
URL rewriting for redirection :
Better to put that in the Apache configuration. using .htaccess is the most flexible way but your Apache conf must allow it, if not, set the rewriting in the Vhost file.
URL rewriting for ressource management :
When it's about managing not found contents, access right or getting clean URL for accessing dynamic contents, you need to set the rewriting in the script file of your app since it's where you have access to the API to handle this kind of things.
So both of the ways are complementary, and you will usually use both at the same time.
.htaccess file in the directory should best place if you dont have any speed optimization concerns. And its also the way to go if your site is hosted on shared webhotel or your web application can create the htaccess files by itself.
Personally i prefer to have every configuration option in the virtualhost config file but thats good only if you have the root access.
It depends if you also need to do outbound URL-rewriting (the modification of links in the actual HTML pages themselves,) in which case, a tool like MOD_REWRITE will not do the trick for you, and you will need to use an "internal" or "native server-side" tool, in the case of Java, you would use something like PrettyFaces, or Rewrite.
These tools can also do the same type of inbound rewriting (like sending redirects to new pages, or forwarding to a new internal resource so that users do not know they are seeing an address/URL change.
My general rule of thumb, however, is that if the URL-rewrite rules need to be available when the application is running, you should use something like MOD_REWRITE, but if the rules only apply to that application itself, then they belong inside the application and you should use a native tool.

Resources