Welcome to WebmasterWorld Guest from 188.8.131.52
I have a site which is totally changing in structure and will no longer use query strings. However I want to redirect these pages with parameters to an equivalent page with a permanent 301.
However if I use the following line of code in my .htaccess file it will append the query string;
redirect 301 /example.php [newexample.com...]
eg. If I try to access the following page;
It will redirect you to [newexample.com...]
It is carrying over the query string when redirecting i.e.?parameter=123
However I donít want the redirect to pass on the query string, how do I stop them from being appended to the new page?
And is there a way to specify a filename with a parameter which I can then redirect?
Im sure i could do this with a regular expression but im not quite sure how.
Think ive solved it using;
RewriteRule ^test/test2.php$ http://www.example.com? [R=301,L]
that is the exact way to replace the querystring. per default RewriteRule will use the original querystring until you define your own: it's a this-or-that situation.
only if you use the [QSA] (= Query String Append) parameter, you can mix both.
I have asked this question before......and the answer for a universal mod rewrite I guess created an endless loop or whatever and it wouldn't work, unless the rule was just wrong.
But I have about 7000 products, hence 7000 urls that I was rewriting a certain way and then changed the method of rewrite to include the item name in the url and shorten the url so it didn't appear that the page was deep in several directories. So I began rewiting them a different way. It now looks like they are top level pages. The jest of this is I'm trying to 301 redirect all of them to their new style.
domain/cp-app/sports-memorabilia/ItemID is now
I made a 301 rewrite rule for each and every one to redirect them, and "I think" it worked, but that meant putting 7000 or so lines in my htaccess file and it ballooned to 1.5 meg in size and slowed my dynamic site to a crawl. I quickly abandoned that method.
Does anyone know of a rewrite or redirect method that would work? I read briefly here on webmasterworld in another thread something about a script or external from the htaccess file to accomplish this but didn't understand it at all.
The bottom line is I am trying to redirect 301 a url that has been written one way to rewriting it another way. If anyone has methods or suggestions I would really really appreciate their help. If it involves a coding or script or something I am willing to talk on the phone and/or to pay someone for their time.
I know I am not the first person who has ever changed the method of rewrite they are using for alot of urls. There must be a method that can solve this issue. I hope someone out there has the knowledge and experience to put me on the right track.
Thanks in advance for your time and help!
RewriteMap can be used to call a script (PERL is used most often) to do a database lookup to translate one URL to another. This is only needed in cases such as yours, where the old URL does not contain all of the information needed to generate the new URl by simple test rearrangement or substitution.
RewriteMaps can be used in .htaccess, but they must be defined at the server configuration level; As such, this solution is not available to sites on name-based or IP-based virtual servers. Usually, you'll need to be hosted on a VPS or a dedicated server to have this level of access.
In that case, you can still use mod_rewrite to rewrite all or most requests to a script, which can then either include and output the desired page content, or generate an external redirect to the correct URL. The first option is 'silent' while the second is visible to the user.
RewriteRule ^cp-app/prod/sports-memorabilia/([^/]*)/?$ shop/cgi-bin/cp-app.cgi?pg=ste_prod&sports-memorabilia&ref=$1 [L]
cp-app is the cgi script, prod is the page (short for product), sports-memorabilia is just a fake dir to put those keywords in the url, ref is the item ID
New rule and url
RewriteRule ^sports-memorabilia-(.*)\.html shop/cgi-bin/cp-app.cgi?seo=item--$1 [L]
Top level page now, sports-memorabilia is again just fake keywords inserted, Jason Varitek Gold Coin Photomint is the items name or <Title> tag, HM-PHOTO323K is the itemID, and of course it now has html added to the end
There is a routine in the shopping cart cgi script as you see that is being called in the second rule that pulls the correct information to create the url.
Is there some way to redirect the first rule to the already existing script using the item id and have it create the corresponding new style url?
Is that along the same track of what you suggested doing?
So if ref and id are not the same thing, you have to use an existing or new database to do the translation. And that's where RewriteMap and a database-access script come in.
You can see in the second method that there is a routine in the cgi script that is being called that is what forumlates the new style url somehow based on the item id it is looking for.
If there is a method to somehow redirect to it, is that what you are thinking?
RewriteRule ^cp-app/prod/sports-memorabilia/([^/]+)/?$ /shop/cgi-bin/cp-app.cgi?seo=item--$1 [L]