473,854 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Redirect URL, keep and add to string...

13 New Member
Hi folks, really hoping someone can help me here...

I'm trying to direct a load of old web pages to one single page that then populates a registration form as necessary. The catch is that it populates the form from a unique URL based argument / string.

Annoyingly all the pages are missing a product name, so I am looking at finding a way to add this name to the URL, from the redirection page.

So my question is... is it possible to use Apache so that when a user visits the old page, they are redirected to a new page, that retains the entire previous unique URL and also adds :PRODUCTNAME to the end?
Jan 11 '11 #1
7 5288
Sudaraka
55 New Member
Depends on where you have the PRODUCTNAME in the old page, if it's a part of the old url, you can just pass the old url to the new page as a parameter in the query string parse it on the new page.

redirect using mod_rewrite using something like this:
Expand|Select|Wrap|Line Numbers
  1. RewriteRule (old_page.html) new_page.php?redirected_from=$1 [QSA]
Jan 11 '11 #2
Stuart Hunter
13 New Member
Thank you for your quick response Sudaraka,

There currently is no product information on the old page. Instead of revising a lot of old files I thought it would be best to redirect them using .htaccess to a new single page.

This page would then call the relevant information from the new url and add the additional information to the form as needed, in this case a product name.

The query so is as below and it would be great to add ':product_name' to the end of it.

The catch here is that the code generated is different everytime, we cannot copy the entire string, but maybe the htm files name would be sufficient?

e.g.

old urls=

"http://www.test.com/product1.htm?01 234:user_name_o ne"
"http://www.test.com/product2.htm?43 210:user_name_t wo"

new urls=
"http://www.test.com/product1.htm?01 234:user_name_o ne:product_name "
"http://www.test.com/product1.htm?01 234:user_name_t wo:product_name "
Jan 11 '11 #3
Sudaraka
55 New Member
Ok, so what you should do is for urls that goes to product[n].html pages capture the page name and append that to the query string like below
Expand|Select|Wrap|Line Numbers
  1. RewriteRule ^(product[0-9]+).htm /product.htm?%{QUERY_STRING}:$1 [R=301,L]
Please note that for this to work your new page must not match the pattern we check for old files (product[n]) otherwise it creates an infinite loop.
Jan 11 '11 #4
Stuart Hunter
13 New Member
I see, that code is fantastic thank you and would be great for the original URLs (and something I will be sure to use in future) but unfortunately the product1.htm is an example, the actual URLs have no similarity so it's separate lines for each instance :(

Within that string Sudaraka would you mind pointing out where I would add :product_name to the new redirect string? Before the $1?

i.e.

Expand|Select|Wrap|Line Numbers
  1. RewriteRule ^product1.htm /product.htm?%{QUERY_STRING}:product_name$1 [R=301,L]
I assume the rewrite will then automatically pick up the product.htm file within the directory saving a redirect?

Sorry about this, I am dusting off my apache and javascript knowledge lately to ensure best practice.
Jan 11 '11 #5
Sudaraka
55 New Member
First, Yes, you can before or even after the $1 as you like.
Please note that $1 refers to the matching blocks from the regular expression match of the current url, and since you have no brackets in there (^product1.htm) $1 will be empty.

Second, if you like to do this without the redirect you can simple get red of the R=301 key, and if there are other url rewrites you do after this you should as PT to pass through the rewrite result done in this section.

Expand|Select|Wrap|Line Numbers
  1. RewriteRule ^(product1).htm /product.htm?%{QUERY_STRING}:product_name:$1 [PT,L]
  2. # or without the reference to old url
  3. RewriteRule ^product1.htm /product.htm?%{QUERY_STRING}:product_name [PT,L]
Jan 11 '11 #6
Stuart Hunter
13 New Member
Perfect, you have a been a fantastic help, thank you so much.

The only addition was to add 'RewriteEngine on'...

Expand|Select|Wrap|Line Numbers
  1. RewriteEngine on
  2. RewriteRule ^product1.htm /product.htm?%{QUERY_STRING}:Product [R=301,L]
...then that all worked a treat :)
Jan 11 '11 #7
Sudaraka
55 New Member
Nice to hear it worked out for you. Glad to help.
Jan 11 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
3316
by: Dmitry Karneyev | last post by:
Hi All! I've got an ado.net app with several win forms. In the first form (form1) I connect to DB and in other forms I use connection string generated by the form1 and stored in sqlconnection object of form1. If I use windows authorization of SQL Server everything works fine, but when I use SQL Server authorization it doesn't work because sqlconnection object doesn't store the password and as a result of retrieving connection string...
1
2403
by: VB Programmer | last post by:
I have a default.aspx page that simply does this (in the "Try" block): Response.Redirect("MyStartPage.aspx") I keep getting this exception on this line: "System.Threading.ThreadAbortException: Thread was being aborted. at System.Threading.Thread.AbortInternal() at System.Threading.Thread.Abort(Object stateInfo) at System.Web.HttpResponse.End() at System.Web.HttpResponse.Redirect(String url, Boolean endResponse) at...
8
3866
by: msnews.microsoft.com | last post by:
I want to redirect the user to a url outside of our website but I want it to preserve our application's window by opening a new window. We have a datagrid that has five hyperlink columns containing links to external sites. The hyperlink columns have the target="_blank" attribute so they preserve the existing window. This works OK except that the NavigateURL's are quite long due to the size of the query string and this makes the page slow. ...
3
7892
by: Peter Row | last post by:
Hi, I better get the background stuff out the way first, so here goes: - Porting a VB6 webclass app to VB.NET using HttpHandlers and FormsAuthentication - When someone visits my site unbeknown to them they are automatically logged in as a guest via the .NET forms authentication.
1
4205
by: EagleRed | last post by:
I am writing an ASP.NET application in which I am using the Response.Redirect() call. I noticed that I catch a ThreadAbort Exception after making the call. Indeed the documentation states that this occurs "Beware! The run time can throw exceptions on its own! For example, Response.Redirect() throws a ThreadAbort exception. Even if you don't explicitly throw exceptions, you may use functions that do. Make sure you check Perfmon to get the...
3
2287
by: neil_pat | last post by:
I have a stored procedure which returns a value of between 0 and 4. I want the user to press a button to receive feed back on their last input. The save button takes the input and saves it to the database. The feedback button runs a stored proc that takes the saved data from the table, performs a logical calcualation and returns the right value between 0 and 4. Depending on the value returned the redirect page is different. Here is...
3
5121
by: Peter Kirk | last post by:
Hi I need to write a method which accepts a url (string) and redirects to it. In addition to this I need to either (a) add a parameter to the url; or (b) add the parameter to the header of the redirect request. To add a parameter I guess it's as easy as adding "?myparam=myvalue" to the url (or "&myparam=myvalue" if there already are parameters in the url string I get).
2
4757
by: Jason Huang | last post by:
Hi, In my .Net 2.0 C# web form Form1, say I have a button btnToForm2. Is the Request.Redirect("Form2") the right way to go to the Form2 in the btnToForm2_Click event? Actually, I also want to pass a parameter from the Form1 to Form2, do I need to declare a global variable for storing? Thanks for help.
56
7264
by: UKuser | last post by:
Hi, I'm not sure if this can be done as I've searched the web and this forum. I am using an online merchant provider and I must post certain variables to their webforms through a form on my website. The issue is that I need to gauge whether a user has any items in their basket to decide which page I redirect them too. I could
3
2347
by: Julien | last post by:
Hi, I can't seem to find the right regular expression to achieve what I want. I'd like to remove all characters from a string that are not numbers, letters or underscores. For example: str: 'si_98udasgf'
0
9903
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9754
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10692
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10767
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7927
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5952
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4567
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4168
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.