Hello Friends...

Now Im working on URL Rewriting...

I got them worked..But i have few doubts about this concept...
Any Experts will reply me here..

My leftproducts.php page have some times s_id query string
and some times along with s_id , start query string also..
means sometimes:

www.something.com/leftproducts.php?s_id=1

And some times

www.something.com/leftproducts.php?s_id=1&start=10

then how can i put conditions on .htaccess file...

If i write rule for both query strings, it doesn't work for one query string...
Please help on this...

Thanks In Advance...

Below is the code for the htaccess file:

RewriteEngine On

RewriteRule ^leftproducts/([^-]+)\.html$ leftproducts.php?s_id=$1
RewriteRule ^leftproducts/([^-]+)-([^-]+)\.html$ leftproducts.php?s_id=$1&start=$2

The above code will rewrite the url to the following two urls, first url for the single $_GET variable and second example url below is for when both $_GET variables are in use.
www.something.com/leftproducts/1.html
www.something.com/leftproducts/1-10.html
Notice the two variables are separated by a dash. Hope it helps.

thanks, its worked before...
And one more doubt...

if i write rule for my site like:

www.mysite.com/shopping/leftproducts/1/20

then the images and css file will not came to display...
i think its because of path could be changed...
then how to get them worked..
tel me any idea...

then the images and css file will not came to display...
i think its because of path could be changed...
then how to get them worked..
tel me any idea...

Lets say for example your page is located at www.mysite.com/shopping/leftproducts/1/20
The page will assume your css files are located at
www.mysite.com/shopping/leftproducts/1/20/file.css
And the same applies for images. To pass by this, when adding images, javascript includes, css includes, simply specify the full url. Example:

<img src='http://www.mysite.com/shopping/image.jpg'>
<script src="http://www.mysite.com/shopping/script.js">

And you can see, I have specified the full url and that is so no matter what virtual directory you are in, the browser can still read the external files.

thank you for your response and clue..
i will work on this...

And one more doubt on rewriting...i think you can solve this...
I had written my site rewriting rule like this:

www.mysite.com/shopping/2-product_name.html

in the above 2 is my query string and product_name is my product name...
is there any way to convert my url like this with only product_name with out leaving id as used in that page..

www.mysite.com/shopping/product_name.html

Means is there any way to hide query string in that url...
please tel me any to solve this..
i need this is very urgent..

thanks again for your response...
shanti.

If you decide to do that you will need to use Session/Cookie/POST data to tell the server what the product is, as you have have 2 or more products with the same name - this will cause issues if you just have the product name.

Send the product id as POST data or assign it to a cookie or the users session and run the query from there (of course, make sure you sanitize/clean the data before the query)

I have made a script in the past that can store url variables as sessions but I don't know how to SEO (Search Engine Optimization) will go on the header redirect. But anyway, this is how my script works. First, place at the top of all files you want to recieve the hidden values the following code:

<? session_start(); 

if (isset($_SESSION['vars']))
    {
    unset($_SESSION['vars']['url']);
    foreach($_SESSION['vars'] AS $keys => $values)
        {
        $_GET[$keys]=$values;
        }
    }
unset($_SESSION['vars']);
unset($keys);
unset($values);

So in your case, the file leftproducts.php or whatever php file serves product_name.html will contain that code at the very top. Then when linking to a page, you need to link to a different page which forwards the session and $_GET information to the visible page. So while keeping that bit of theory in mind, make a file named linker.php and place the following code in it:

<?
session_start();
if (!empty($_GET))
    {
    unset($_SESSION['vars']);
    $tmp=$_GET;
    $_SESSION['vars']=$tmp;
    }
header('Location: '.$_GET['url']);
?>

Now for the confusing bit, to link to a page with this system. When linking to a page, use the following code:

<?
//url to link to
$url="http://www.mysite.com/shopping/product_name.html";
//hidden id number
$id=2;
//and below is the link
?>
<a href='linker.php?url=<? echo $url; ?>&id=<? echo $id; ?>'>Link Title</a>

Hope that answers your question because yes it is possible.

can any body tel me any other ways to hide query strings in my url....
because my url contains 3 or more query strings to be passed...

thanks in advance...

i need more information on this...
please help me...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.