domain.com/12354 to domain.com/~one/cart/cart.cgi/12345.html

Discuss practical ways rearrange URLs using mod_rewrite.

domain.com/12354 to domain.com/~one/cart/cart.cgi/12345.html

Postby sergv » Tue Apr 05, 2005 8:22 pm

The part of ~one/cart/cart.cgi always stays the same...
Thanks!
sergv
 
Posts: 10
Joined: Tue Mar 15, 2005 9:20 pm

Postby Caterham » Wed Apr 06, 2005 4:07 am

Have a try on
Code: Select all
RewriteEngine On
RewriteRule ^([0-9]+)/?$ /~one/cart/cart.cgi/$1.html [L]


If you're using mod_aloas or mod_userdir, use

RewriteEngine On
RewriteRule ^([0-9]+)/?$ /~one/cart/cart.cgi/$1.html [PT,L]
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm

Postby sergv » Wed Apr 06, 2005 8:06 pm

I tried both of those....maybe i just don't get the whole mod_rewrite deal...The code above-where do I put it? Once i plug the code into the server, i should be able to access my files the following way:

www.domain.com/12345

Correct? The above will be the same thing as saying

www.domain.com/~one/cart/cart.cgi/12345.html
without rewrite, correct?

Thanks!
sergv
 
Posts: 10
Joined: Tue Mar 15, 2005 9:20 pm

Postby Caterham » Thu Apr 07, 2005 12:54 pm

Once i plug the code into the server
and where did you put it? In httpd.conf? in a .htaccss file?
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm

Postby sergv » Thu Apr 07, 2005 5:05 pm

.htaccss
sergv
 
Posts: 10
Joined: Tue Mar 15, 2005 9:20 pm

Postby Caterham » Sun Apr 10, 2005 5:04 am

there was a misspelling above, it should be .htaccess

Did you also try the 2nd part,
RewriteEngine On
RewriteRule ^([0-9]+)/?$ /~one/cart/cart.cgi/$1.html [PT,L]
What kind of error did you get if you call http//example.com/1234?
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm

Postby sergv » Mon Apr 11, 2005 4:35 pm

Of course you're correct! I misspelled a directory :( THANKS!

Now how bout this one:
http//example.com/SearchTerm into

http//example.com/~one/cart/cart.cgi/scan/sp=product_listing/fi=products/st=db/co=yes/sf=prod_group/se=SearchTerm/tf=category/ml=10/va=prod_group=SearchTerm/va=cats=.html

SearchTerm could be anything, including a word with spaces (such as Search Term)


Thanks in advance!
sergv
 
Posts: 10
Joined: Tue Mar 15, 2005 9:20 pm

Postby Caterham » Tue Apr 12, 2005 1:47 pm

Of course you're correct! I misspelled a directory
I ment my posting...
I wrote
.htaccss which should be
.htaccess

try
RewriteRule ^([^.]+) /~one/cart/cart.cgi/scan/sp=product_listing/fi=products/st=db/co=yes/sf=prod_group/se=$1/tf=category/ml=10/va=prod_group=SearchTerm/va=cats=.html [L]
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm

Postby sergv » Tue Apr 12, 2005 4:19 pm

Ya, u had a misspel and so did i in my .htaccess file :)
I use the last rule with a slight modification
RewriteRule ^([^.]+)/?$ /~....
and it worked. One question I have is how is it possible to do following:

I have a 2(or more) word search term (for simplicity lets call it Search Term) that needs to look like http//example.com/Search-Term.html and rewritten into the above string with se=Search Term (with a space), how would i go about that? I guess i have to take the - and sub it for a space and then strip out .html, but not sure how i can do that...

and the very last one...just like the example above, except i want to have 2 terms that should be accessed like:

http//example.com/Search-Term1/Search-Term2.html
into
http//example.com/~on.../se=Search Term 1/se=Search Term 2

(the ... represents the rest of the string that I think i know how to do)
What if the Search Term 1 has a '/' in it, such as Search/Term 1?
once again caterham, thanks a lot for ur help!
sergv
 
Posts: 10
Joined: Tue Mar 15, 2005 9:20 pm

Postby Caterham » Sun Apr 17, 2005 1:52 pm

I have a 2(or more) word search term (for simplicity lets call it Search Term) that needs to look like http//example.com/Search-Term.html and rewritten into the above string with se=Search Term (with a space), how would i go about that? I guess i have to take the - and sub it for a space and then strip out .html, but not sure how i can do that...
I wouldn't recommend to use mod_rewrite here, PHP might be the better place, because this might cause problems.

and the very last one...just like the example above, except i want to have 2 terms that should be accessed like:

Code: Select all
RewriteRule ^([^~-]+)-([^-]+)\.html$ /$1\ $2.html [L]

RewriteRule ^([^~/]+)/([^./]+) /~one/cart/cart.cgi/scan/sp=product_listing/fi=products/st=db/co=yes/sf=prod_group/se=$1/se=$2/tf=category/ml=10/va=prod_group=SearchTerm/va=cats=.html [L]

RewriteRule ^([^.~]+) /~one/cart/cart.cgi/scan/sp=product_listing/fi=products/st=db/co=yes/sf=prod_group/se=$1/tf=category/ml=10/va=prod_group=SearchTerm/va=cats=.html [L]
What if the Search Term 1 has a '/' in it, such as Search/Term 1?
this will nor work if the Search Term contains a ~ . in general and a / for rule #2
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 14 guests

cron