You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Ki Song <ki...@knifecenter.com> on 2007/11/13 18:10:16 UTC
[users@httpd] 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@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Mod_Rewrite from old dynamic page
Posted by Martijn <sw...@googlemail.com>.
On Nov 14, 2007 5:03 PM, Ki Song <ki...@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@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Mod_Rewrite from old dynamic page
Posted by Ki Song <ki...@knifecenter.com>.
> 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@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
RE: [users@httpd] Mod_Rewrite from old dynamic page
Posted by Axel-Stephane SMORGRAV <Ax...@europe.adp.com>.
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@knifecenter.com]
Envoyé : mardi 13 novembre 2007 23:40
À : Apache List
Objet : Re: [users@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@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@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@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Mod_Rewrite from old dynamic page
Posted by Ki Song <ki...@knifecenter.com>.
>> 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@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Mod_Rewrite from old dynamic page
Posted by Martijn <sw...@googlemail.com>.
On Nov 13, 2007 7:43 PM, Ki Song <ki...@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@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Mod_Rewrite from old dynamic page
Posted by Ki Song <ki...@knifecenter.com>.
>> 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@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Mod_Rewrite from old dynamic page
Posted by Martijn <sw...@googlemail.com>.
On Nov 13, 2007 6:07 PM, Ki Song <ki...@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@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Mod_Rewrite from old dynamic page
Posted by Ki Song <ki...@knifecenter.com>.
>> 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@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Mod_Rewrite from old dynamic page
Posted by Martijn <sw...@googlemail.com>.
On Nov 13, 2007 5:10 PM, Ki Song <ki...@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@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org