LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-15-2008, 12:01 AM   #1
kilaz
LQ Newbie
 
Registered: Dec 2004
Posts: 3

Rep: Reputation: 0
.htaccess - how do I strip characters from a dynamic url? using Mod_rewrite


Hi,
I'm switching E-commerce software and the new cart uses a similar URL compared to the old cart minus one bit of information.

I'd like to convert any inbound request for the old URL to the new URL without having to put a redirect for each possible URL(Over 700) products.

The old url looks like this.

http://www.domain.com/product-name-p-529.html

the -p-529 will vary since that's the product #, The new site doesn't need that information.

the new url looks like this.

http://www.domain.com/product-name.html

Basically what I need is a way to strip the -p-529 from the any incoming url and redirect to the new url.

Any ideas?

Thanks in Advance...
-K-
 
Old 10-15-2008, 12:12 AM   #2
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
RewriteEngine on
RewriteCond %{REQUEST_URI} ^.*product-name(.*)$
RewriteRule .* product-name.html

That should work.
 
Old 10-15-2008, 02:47 AM   #3
kilaz
LQ Newbie
 
Registered: Dec 2004
Posts: 3

Original Poster
Rep: Reputation: 0
Hi Jim, Thanks for the reply. I didn't leave enough details. The product name vary also.

so for example

widget-blue-p-529.html
wonder-bar-large-p-123.html
blow-up-doll-p-691.html

would have to be stipped of the -p-###.html so they look like this.

widget-blue.html
wonder-bar-large.html
blow-up-doll.html

I'd like to have one rule that just takes any inbound request with the -p-###.html and just strip's the product ID (-p-###.html) instead of having to create a rule for each products URL.

-K-

Last edited by kilaz; 10-15-2008 at 03:28 PM.
 
Old 10-15-2008, 12:28 PM   #4
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
You can do that as a variant of what I gave you. Study the rules for regular expression processing in RewriteCond and RewriteRule.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ - parsing windows textfile: how to strip extra characters? babag Programming 4 05-19-2008 07:57 PM
mod_rewrite url redirection sqn Linux - Software 2 10-04-2006 08:39 AM
Strip special characters from filenames General Linux - Software 1 05-14-2006 03:49 AM
.htaccess mod_rewrite issue Jukas Linux - Software 2 12-13-2005 12:23 PM
Suse 9.1 Pro & htaccess file: mod_rewrite not loading sorenson2743 SUSE / openSUSE 2 12-03-2004 11:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration