Problem in Static URL generation

New to mod_rewrite? This is a good place to start.

Problem in Static URL generation

Postby LakkadBabu » Mon Oct 26, 2009 10:09 pm

Hi,
I want to generate static URL for particular page. I am new to mod-rewrite. even after studying the tutorials I don't understand how to do the following for the comparison page

When products are compared it puts comparison with its own url for eg.
mydomain.com/compare-prod1-and-prod2-and-prod3

I am using min 2 and max 5 products for comparison. product_id's (array)are to be submitted through a form. That is all working fine. But I am blank in static URL generation.

Please Help.
LakkadBabu
 
Posts: 5
Joined: Mon Oct 26, 2009 9:41 pm

Postby richardk » Tue Oct 27, 2009 11:47 am

product_id's (array)are to be submitted through a form

What type of <form> is it (method="get" or method="post")?

I am using min 2 and max 5 products for comparison.

The mod_rewrite would be something like
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^compare-([^-/]+)-and-([^-/]+)(?:-and-([^-/]+)(?:-and-([^-/]+)(?:-and-([^-/]+))?)?)?$ /compare?p1=$1&p2=$2&p3=$3&p4=$4&p5=$5 [QSA,L]

to make /compare-prod1-and-prod2-and-prod3 go to /compare?p1=prod1&p2=prod2&p3=prod3.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby LakkadBabu » Tue Oct 27, 2009 9:13 pm

I am using method POST in the form.

I have used the code you mentioned but still it is not working.

it is simply displaying the name of the file in the URL:

mydomain.com/compare_prod.php
LakkadBabu
 
Posts: 5
Joined: Mon Oct 26, 2009 9:41 pm

Postby LakkadBabu » Wed Oct 28, 2009 1:53 am

Do we have to make some changes in our php files to achieve this?
LakkadBabu
 
Posts: 5
Joined: Mon Oct 26, 2009 9:41 pm

Postby richardk » Wed Oct 28, 2009 11:21 am

I am using method POST in the form.

You will either need to change the <form> action="" to a PHP script to redirect to the new URL or you will need to change the <form> method="" to GET so mod_rewrite can match the query string.

I have used the code you mentioned but still it is not working.

What happens when you go to /compare-prod1-and-prod2-and-prod3?

Code: Select all
/compare?p1=$1&p2=$2&p3=$3&p4=$4&p5=$5

needs changing to the working URL for the comparison page.

Do we have to make some changes in our php files to achieve this?

You will need to change the script to accept GET input instead of POST input.
If links are outputted anywhere, they need to be outputted as the new URLs not the old URLs.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby LakkadBabu » Sun Nov 01, 2009 2:11 pm

I have changed my form method to GET .

May be I was unable to put in a right way.

I am fetching two variables array. One is the product ID and another is the name of the product name.

after channg method to post the url it is showing is:

compare_prod.php?compare[]=70&product_name[]=Pm+2&compare[]=69&product_name[]=Pm+Test&compare[]=68&product_name[]=Rocker&compare[]=71&product_name[]=Rocker2&product_name[]=rrr&product_name[]=Test1

in this case how can I achieve URl like this:

/compare-prod1-and-prod2-and-prod3 and so on
LakkadBabu
 
Posts: 5
Joined: Mon Oct 26, 2009 9:41 pm

Postby richardk » Mon Nov 02, 2009 10:32 am

Does this URL work? Have you changed the script to use $_GET instead of $_POST?

What is the value of "prod1", "prod1" and "prod3"? Is it just the product_name[] or does it include the compare[] variable as well (is it compare-Pm+2-Pm+Test, compare-70-69 or compare-Pm+2-70-Pm+Test-69)? The last one is easiest.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby LakkadBabu » Mon Nov 02, 2009 9:53 pm

richardk wrote:Does this URL work? Have you changed the script to use $_GET instead of $_POST?

What is the value of "prod1", "prod1" and "prod3"? Is it just the product_name[] or does it include the compare[] variable as well (is it compare-Pm+2-Pm+Test, compare-70-69 or compare-Pm+2-70-Pm+Test-69)? The last one is easiest.


Yes I have changed the script to $_GET

Now I am having passing two independent values to compare_prod.php file from index.php one is the compare[] and another is prod_name[].

I want to display
compare/prod_name[]-and-prod_name[]....ans so on

I don't want to display compare[] (this holds the ids of the product choosen for the comparison) in the URL but want these compare ids to show further details in the same page.

if it is not possible then can we display the url like this :
compare/70/Pm 2-and-69/PM Test-and-.... so on

but even in this case what is the form action what be written there?

I am totally confuse.
LakkadBabu
 
Posts: 5
Joined: Mon Oct 26, 2009 9:41 pm


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 18 guests

cron