Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Apache: Users

Mod_Rewrite from old dynamic page

 

 

Apache users RSS feed   Index | Next | Previous | View Threaded


ki at knifecenter

Nov 13, 2007, 9:10 AM

Post #1 of 10 (163 views)
Permalink
Mod_Rewrite from old dynamic page

How would I write a mod_rewrite rule for the following:
OLD URL: http://store.knifecenter.com/pgi-ProductSpec?productSKU
NEW URL: http://www.knifecenter.com/kc_new/store_detail.html?s=productSKU

Is there a way to pass the productSKU to the new url?



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe[at]httpd.apache.org
" from the digest: users-digest-unsubscribe[at]httpd.apache.org
For additional commands, e-mail: users-help[at]httpd.apache.org


sweetwatergeek at googlemail

Nov 13, 2007, 9:25 AM

Post #2 of 10 (156 views)
Permalink
Re: Mod_Rewrite from old dynamic page [In reply to]

On Nov 13, 2007 5:10 PM, Ki Song <ki[at]knifecenter.com> wrote:
> How would I write a mod_rewrite rule for the following:
> OLD URL: http://store.knifecenter.com/pgi-ProductSpec?productSKU
> NEW URL: http://www.knifecenter.com/kc_new/store_detail.html?s=productSKU
>
> Is there a way to pass the productSKU to the new url?

How about:

RewriteCond %{HTTP_HOST} ^store.knifecenter.com$ [NC]
RewriteCond %{QUERY_STRING} ^(.*)$ [NC]
RewriteRule ^pgi-ProductSpec$
http://www.knifecenter.com/kc_new/store_detail.html?s=%1

(I haven't checked this.)

In human language: the first line checks if the host is
store.knifecenter.com, the second line puts the full query_string (the
bit after the ? in the URL) into %1 and the second line does the
actual rewriting.

Martijn.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe[at]httpd.apache.org
" from the digest: users-digest-unsubscribe[at]httpd.apache.org
For additional commands, e-mail: users-help[at]httpd.apache.org


ki at knifecenter

Nov 13, 2007, 10:07 AM

Post #3 of 10 (156 views)
Permalink
Re: Mod_Rewrite from old dynamic page [In reply to]

>> How would I write a mod_rewrite rule for the following:
>> OLD URL: http://store.knifecenter.com/pgi-ProductSpec?productSKU
>> NEW URL: http://www.knifecenter.com/kc_new/store_detail.html?s=productSKU
>>
>> Is there a way to pass the productSKU to the new url?
>
> How about:
>
> RewriteCond %{HTTP_HOST} ^store.knifecenter.com$ [NC]
> RewriteCond %{QUERY_STRING} ^(.*)$ [NC]
> RewriteRule ^pgi-ProductSpec$
> http://www.knifecenter.com/kc_new/store_detail.html?s=%1
>
> (I haven't checked this.)
>
So far, it's working beautifully! Thanks!
How would I write a second rule for:
OLD URL: http://store.knifecenter.com/pgi-Product Spec?productSKU
NEW URL: http://www.knifecenter.com/kc_new/store_detail.html?s=productSKU

Basically, it is the same OLD URL, except there is a space between Product
and Spec. Please note both 'pgi-ProductSpec' and 'pgi-Product Spec' need to
be rewritten.



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe[at]httpd.apache.org
" from the digest: users-digest-unsubscribe[at]httpd.apache.org
For additional commands, e-mail: users-help[at]httpd.apache.org


sweetwatergeek at googlemail

Nov 13, 2007, 10:27 AM

Post #4 of 10 (155 views)
Permalink
Re: Mod_Rewrite from old dynamic page [In reply to]

On Nov 13, 2007 6:07 PM, Ki Song <ki[at]knifecenter.com> wrote:
> How would I write a second rule for:
> OLD URL: http://store.knifecenter.com/pgi-Product Spec?productSKU
> NEW URL: http://www.knifecenter.com/kc_new/store_detail.html?s=productSKU
>
> Basically, it is the same OLD URL, except there is a space between Product
> and Spec. Please note both 'pgi-ProductSpec' and 'pgi-Product Spec' need to
> be rewritten.

Changing the last line to this probably works:
RewriteRule ^pgi-Product(\ )?Spec$
http://www.knifecenter.com/kc_new/store_detail.html?s=%1
If not, try to replace (\ ) by (\s).

(\ )? means: a space or nothing, so it should match both your cases.
Note that, in the URL you see in the browser, spaces are converted to
%20, but in the URL that is parsed by mod_rewrite, they are converted
back.

Martijn.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe[at]httpd.apache.org
" from the digest: users-digest-unsubscribe[at]httpd.apache.org
For additional commands, e-mail: users-help[at]httpd.apache.org


ki at knifecenter

Nov 13, 2007, 11:43 AM

Post #5 of 10 (153 views)
Permalink
Re: Mod_Rewrite from old dynamic page [In reply to]

>> How would I write a second rule for:
>> OLD URL: http://store.knifecenter.com/pgi-Product Spec?productSKU
>> NEW URL: http://www.knifecenter.com/kc_new/store_detail.html?s=productSKU
>>
>> Basically, it is the same OLD URL, except there is a space between Product
>> and Spec. Please note both 'pgi-ProductSpec' and 'pgi-Product Spec' need to
>> be rewritten.
>
> Changing the last line to this probably works:
> RewriteRule ^pgi-Product(\ )?Spec$
> http://www.knifecenter.com/kc_new/store_detail.html?s=%1
> If not, try to replace (\ ) by (\s).
>
> (\ )? means: a space or nothing, so it should match both your cases.
> Note that, in the URL you see in the browser, spaces are converted to
> %20, but in the URL that is parsed by mod_rewrite, they are converted
> back.
>
EXCELLENT!

I've made that change and it works perfectly.

One final issue:
For some reason, the productSKU in the old url was frequently followed by a
',' (comma). So, for example, http://store.knifecenter.com/pgi-Product
Spec?productSKU, would be a valid url in the old system.

Is there a way to "drop" the trailing ',' in the old url?



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe[at]httpd.apache.org
" from the digest: users-digest-unsubscribe[at]httpd.apache.org
For additional commands, e-mail: users-help[at]httpd.apache.org


sweetwatergeek at googlemail

Nov 13, 2007, 2:26 PM

Post #6 of 10 (152 views)
Permalink
Re: Mod_Rewrite from old dynamic page [In reply to]

On Nov 13, 2007 7:43 PM, Ki Song <ki[at]knifecenter.com> wrote:
> For some reason, the productSKU in the old url was frequently followed by a
> ',' (comma). So, for example, http://store.knifecenter.com/pgi-Product
> Spec?productSKU, would be a valid url in the old system.
>
> Is there a way to "drop" the trailing ',' in the old url?

Again, untested, but I would think changing the second line to
RewriteCond %{QUERY_STRING} ^(.*),?$ [NC]
would do the trick.

Though in this case it might be safer to just (re)write your web
application so that it removes a trailing comma if it occurs: this way
you won't get an error, even if a comma slips though the maze. (People
might changes their links to a new URL but accidentally leave the
comma there.)

Martijn.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe[at]httpd.apache.org
" from the digest: users-digest-unsubscribe[at]httpd.apache.org
For additional commands, e-mail: users-help[at]httpd.apache.org


ki at knifecenter

Nov 13, 2007, 2:40 PM

Post #7 of 10 (154 views)
Permalink
Re: Mod_Rewrite from old dynamic page [In reply to]

>> For some reason, the productSKU in the old url was frequently followed by a
>> ',' (comma). So, for example, http://store.knifecenter.com/pgi-Product
>> Spec?productSKU, would be a valid url in the old system.
>>
>> Is there a way to "drop" the trailing ',' in the old url?
>
> Again, untested, but I would think changing the second line to
> RewriteCond %{QUERY_STRING} ^(.*),?$ [NC]
> would do the trick.
>
> Though in this case it might be safer to just (re)write your web
> application so that it removes a trailing comma if it occurs: this way
> you won't get an error, even if a comma slips though the maze. (People
> might changes their links to a new URL but accidentally leave the
> comma there.)

It did not work.
RewriteCond %{QUERY_STRING} ^(.*),?$ [NC]

This code left the trailing , in to rewritten url:
OLD: http://store.knifecenter.com/pgi-ProductSpec?productSKU,
NEW: http://www.knifecenter.com/kc_new/store_detail.html?s=productSKU,

Any other solutions?



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe[at]httpd.apache.org
" from the digest: users-digest-unsubscribe[at]httpd.apache.org
For additional commands, e-mail: users-help[at]httpd.apache.org


Axel-Stephane.SMORGRAV at europe

Nov 13, 2007, 10:51 PM

Post #8 of 10 (148 views)
Permalink
RE: Mod_Rewrite from old dynamic page [In reply to]

Try this instead:

RewriteCond %{QUERY_STRING} ^([^,]*) [NC]

If it still does not work, bump the RewriteLogLevel to 9 and look for answers in the log file.

-ascs

-----Message d'origine-----
De : Ki Song [mailto:ki[at]knifecenter.com]
Envoyé : mardi 13 novembre 2007 23:40
À : Apache List
Objet : Re: [users[at]httpd] Mod_Rewrite from old dynamic page

>> For some reason, the productSKU in the old url was frequently
>> followed by a ',' (comma). So, for example,
>> http://store.knifecenter.com/pgi-Product
>> Spec?productSKU, would be a valid url in the old system.
>>
>> Is there a way to "drop" the trailing ',' in the old url?
>
> Again, untested, but I would think changing the second line to
> RewriteCond %{QUERY_STRING} ^(.*),?$ [NC] would do the trick.
>
> Though in this case it might be safer to just (re)write your web
> application so that it removes a trailing comma if it occurs: this way
> you won't get an error, even if a comma slips though the maze. (People
> might changes their links to a new URL but accidentally leave the
> comma there.)

It did not work.
RewriteCond %{QUERY_STRING} ^(.*),?$ [NC]

This code left the trailing , in to rewritten url:
OLD: http://store.knifecenter.com/pgi-ProductSpec?productSKU,
NEW: http://www.knifecenter.com/kc_new/store_detail.html?s=productSKU,

Any other solutions?



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe[at]httpd.apache.org
" from the digest: users-digest-unsubscribe[at]httpd.apache.org
For additional commands, e-mail: users-help[at]httpd.apache.org


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe[at]httpd.apache.org
" from the digest: users-digest-unsubscribe[at]httpd.apache.org
For additional commands, e-mail: users-help[at]httpd.apache.org


ki at knifecenter

Nov 14, 2007, 9:03 AM

Post #9 of 10 (145 views)
Permalink
Re: Mod_Rewrite from old dynamic page [In reply to]

> Try this instead:
>
> RewriteCond %{QUERY_STRING} ^([^,]*) [NC]
>
> If it still does not work, bump the RewriteLogLevel to 9 and look for answers
> in the log file.

I tried that code and it didn't work.
I saw that there may be some typos, so I tried the following:

RewriteCond %{QUERY_STRING} ^([^,$]*)$ [NC]

That didn't work either.

Any other suggestions?



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe[at]httpd.apache.org
" from the digest: users-digest-unsubscribe[at]httpd.apache.org
For additional commands, e-mail: users-help[at]httpd.apache.org


sweetwatergeek at googlemail

Nov 14, 2007, 9:23 AM

Post #10 of 10 (147 views)
Permalink
Re: Mod_Rewrite from old dynamic page [In reply to]

On Nov 14, 2007 5:03 PM, Ki Song <ki[at]knifecenter.com> wrote:
> > Try this instead:
> >
> > RewriteCond %{QUERY_STRING} ^([^,]*) [NC]
> >
> > If it still does not work, bump the RewriteLogLevel to 9 and look for answers
> > in the log file.
>
> I tried that code and it didn't work.

Did you turn on logging, as suggested? It works fine with me: it
matches the full query string until the first comma occurs. So it'd be
interesting to see what your Rewrite log says.

> I saw that there may be some typos, so I tried the following:
>
> RewriteCond %{QUERY_STRING} ^([^,$]*)$ [NC]

That's bound not to work. A $ in a regular expression means the end of
the string.

Martijn.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe[at]httpd.apache.org
" from the digest: users-digest-unsubscribe[at]httpd.apache.org
For additional commands, e-mail: users-help[at]httpd.apache.org

Apache users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.