hi,

I am created 3 tables for
1> category
2> subcategory
3> projectdetail

In my website folder structure

root-index.php, header.php footer.php

folder- about -index.php and other files

folder - project- index.php

folder - err- 404.php

In my php page project/index.php

i make left column dynamic, i.e call value from table

e.g

School project ( this is category) and href link is project/School project
xyz (subcategory) and href link is project/xyz
abc and href link is project/abc

College project
www
yyy

I want do like when click on link project/School project
It should display that project
but id gives me error 404 page.
Not to create folder for school project or xyz or abc

How to do like when click on link it should display that value from database.
How create dynamic link without creating new php page??
How to do that??

my .htaccess file is

Options +FollowSymLinks

RewriteEngine On
ErrorDocument 404 http://www.aaa.com/err/404.html
RewriteRule ^([^.]+).html$ $1.php [QSA,L]

you can create a dynamic link on the bases of field name,id like you have project.php and there are three projects in db
e.g
fetch from db and put in a variable

$project_name='english'; 
$project_name='math';
$project_name='science';

for three courses saved in database

now you want to show details on project.php with different urls

so link will be <a href="www.mysite.com/projects/<?$project_name?>/" ><?$project_name?></a> as href or page action

and use htacces file
for url rewriting like

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^projects/(.*)/$ project.php?project_id=$1 [L]

request that project id in new page as $project_id=$_REQUEST['project_id']; and do what ever you want

now you are using one php page project.php
but there will be three different links

www.mysite.com/projects/english/
www.mysite.com/projects/math/
www.mysite.com/projects/science/

these examples are just to give you idea

hi,

In my folder - project- index.php

Fetching all data

<a href="www.mysite.com/projects/<?$project_name?>/" ><?$project_name?></a>

It shows like

link:- www.mysite.com/projects/School project/ name:- School project
link:- www.mysite.com/projects/xyz/ name:- xyz
link:- www.mysite.com/projects/abc/ name:- abc


My .htaccess file

Options +FollowSymlinks 

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^projects/(.*)/$ index.php?project_id=$1 [L]

RewriteRule ^([^.]+).html$ $1.php [QSA,L]
RewriteRule ../index.html [L]

when click on link it gives error
The requested URL was not found on this server.

My question is you are giving $project_name in link
so how you get

$project_id=$_REQUEST['project_id'];

please explain??

No you are not getting my point

Look when you are using link for example

<a href="www.mysite.com/projects/<?$project_name?>/" ><?$project_name?></a>

the link made by this should be as

www.mysite.com/projects/School-project/

the spaces are not allowed in url so if you have space in your project name use string replace function and replace them with "-" not underscors as "-" is more effective for search engines.

when we will go at htacces file as

Options +FollowSymlinks 

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
[B]RewriteRule ^projects/(.*)/$ index.php?project_id=$1 [L][/B]

understand the meaning of bold url rewrite rule

that means when it got www.mysite.com/projects/ and (.*)=parameter that passes and that is project name means

projects/(.*)=www.mysite.com/projects/School-project/

then redirect this url to index.php and the project name that is 1st parameter put the value of that in project_id variable

means

at this stage project_id='School-project';

now request the project_id variable on detail page $project_id=$_REQUEST['project_id']; this $project_id is just variable name it contains the value of project name not ID

now again apply string replace function on $project_id and replace that "-" with "%" that will help you to apply LIKE command for sql quesry

after apply replace function it will be $proj_name="school%project"; now apply the select query like

select project_id from table-project where project_name [B]like[/B] '$proj_name% or 

project_name like 'school%name%'

that will match each word

now you will get the ID of that project name and use that if for your required results.

All this process is for proper url re-writing for dynamic urls

hi,
can you please explain briefly...with example...
I am doing same as you suggested...

Aamit i can explain it briefly with example but now i have to go. if you can wait i can send you the example tomorrow.

can you wait

Yes. sure

Can you post full code with htaccess??

hello amit. i have done it for you. i am attaching a folder. use it at your localhost. and tell me whats the results.

i have made a database with single table. database backup is also in the folder. just use the database and run the file.

htaccess file is also there. All the work is done. just see the folder.

i am here for further help

Wait for my replay i am going through your code...

ok m here but hurry up... :)

Thank You Thank You Thank You Thank You Thank You
Very Much...

You r rock star...

It perfectly work on localhost...

I integrating on live if i found any difficulty with htaccess i will tell you

Thanks for your help...god bless you

:) no no its really ok. I always feel so happy when i be able to help others. please feel free to ask any question.

i will be happy if you will write your kind remarks in my reputation

Add to BzzBee's Reputation about my posts

hi,
In htaccess

RewriteEngine on
RewriteBase /project_test/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^projects/(.*)/$ project_detail.php?pname=$1 [L]

and my project_detail.php file at
http://localhost/demo/abc/index.php
http://localhost/demo/abc/project_detail.php
when click on link
http://localhost/demo/abc/projects/school-project/
IT gives page not found

I think some modification needed at this line

RewriteRule ^projects/(.*)/$ project_detail.php?pname=$1 [L]

plz tell me what to do??

hi,
In htaccess

RewriteEngine on
RewriteBase /project_test/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^projects/(.*)/$ project_detail.php?pname=$1 [L]

and my project_detail.php file at
http://localhost/demo/abc/index.php
http://localhost/demo/abc/project_detail.php
when click on link
http://localhost/demo/abc/projects/school-project/
IT gives page not found

I think some modification needed at this line

RewriteRule ^projects/(.*)/$ project_detail.php?pname=$1 [L]

plz tell me what to do??

Try making the following your .htaccess file:

RewriteEngine on

RewriteRule ^projects/(.*)/$ project_detail.php?pname=$1

Also make sure that mod_rewrite is enabled in the apachie configurations.

hi,
In htaccess

RewriteEngine on
RewriteBase /project_test/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^projects/(.*)/$ project_detail.php?pname=$1 [L]

and my project_detail.php file at
http://localhost/demo/abc/index.php
http://localhost/demo/abc/project_detail.php
when click on link
http://localhost/demo/abc/projects/school-project/
IT gives page not found

I think some modification needed at this line

RewriteRule ^projects/(.*)/$ project_detail.php?pname=$1 [L]

plz tell me what to do??

hello amit

look, when we are in root directory means www the rewrite base will be as

RewriteBase /

when you are in demo folder with in the root directory so the rewite base will be as

RewriteBase /demo/

as same in your case it should be

RewriteBase /demo/abc/

now try it

RewriteEngine on
RewriteBase /demo/abc/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^projects/(.*)/$ project_detail.php?pname=$1 [L]

RewriteEngine on

RewriteRule ^projects/(.*)/$ project_detail.php?pname=$1

hello Amit,

Is you issue solved or not?

commented: Great comments to enforce the rules +3

BzzBee that script worked great !! I do have a question how can we add title and description to metag tags. for each page created example page:
mydomain.com/web-design-software/
I would want to have Title: Web Design Software
Description: All you need to know about Web Design

I tired echo

<title><?php echo $pname ?> </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="description" content="<?php echo $project_other_info ?>" />
  <meta name="keywords" content="<?php echo $tagz=$rowp['tagz']; ?>" />

But that just brings the title as web-design-software
And the Description - Keywords just shows blank.

Any help would be appreciated .
Thanks

Will you please help me how can i change my link by .htaccess?
My link is like http://localhost/root/?page=index i want to see it as http://localhost/Jagobandhu/index/ when im am in index page or http://localhost/Jagobandhu/contact/ when i am in contact page like as CMS.

I have no idea about .htaccess
I tried with this
RewriteEngine on
RewriteBase /project_test/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^root/(.*)/$ root?page=index [L]

but i failed every time. PLease if possible help me.My page links are like

<li><a href="?page=index">Home</a></li> <li><a href="?page=about">About</a></li> <li><a href="?page=contact">Contact</a></li> <li><a href="?page=song">Songs</a> </li>

Hello Everyone,

                            I tried above code but in my side it is not working. 
                           I want to create one page with different different url. like
                           www.example.com/city/Dehli , www.example.com/city/Chandigarh.

                           So i want to create only one page like city.php and change city name there according to choices and url will change according to city name, only one page. i don't want to use database . only simple html and php page.

Is this possible?

when i used url link www.example.com/city/index.php/Dehli then it work otherwise show 404 not found error

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.