Hi..!

I am having a list of members in my database, which i want to display in my website.

I am using php GET method, and the sample url is

http://www.mywebsite.com/display.php?id=564

Can anyone please help me in getting url like

http://www.mywebsite.com/munna_bharadwaj_564

I may not describe my question properly, but, hope you can understand...
Thanking you..
Bharadwaj

Recommended Answers

This depends about the munna_bharadwaj bit.
Apache mod_rewriting can take care of the number bit easily enough.

You could do something like this:

RewriteEngine On
RewriteRule ^munna_bharadwaj_([^/]*)/$ /display.php?id=$1 [L]

But I suspect you'd want a different name/term for each number?

BTW this 'code' won't change the original url, it …

Jump to Post

OK, I see. Like Daniweb?

Jump to Post

All 8 Replies

Member Avatar

This depends about the munna_bharadwaj bit.
Apache mod_rewriting can take care of the number bit easily enough.

You could do something like this:

RewriteEngine On
RewriteRule ^munna_bharadwaj_([^/]*)/$ /display.php?id=$1 [L]

But I suspect you'd want a different name/term for each number?

BTW this 'code' won't change the original url, it will just allow the smarter url to be read as the original.

"munna bharadwaj" is the name...
for example, see the url of this page, It is

...hp/threads/454418/display-name-in-url-from-sql

I want this type of url...
but, in my trails, i am getting

...hp/threads.php?id=454418

I want the php code for the first mentioned kind of urls...

Member Avatar

OK, I see. Like Daniweb?

Yes, and, actually many websites use the same, especially the e commerce websites. Using that kind of URLs will make my website and database a bit safe from hackers. So, can you/ anyone help me in getting urls like that...

ok, i understood your explaaination, you mean to add ".htaccess file" right..? thank you... :)

Member Avatar

THe title AFAIK is not essential to the url - maybe for SEO purposes. Yep the .htaccess file will be handling the rewrite. Remember you will be writing the smart urls into your pages and then .htaccess allows the server to make sense of them, i.e. extract the parameters.

Member Avatar

I'm no expert so bear with me:

RewriteRule ^/([^/]*)/[^/]*/$ /threads.php?id=$1 [L]

I think may do it.

Using that kind of URLs will make my website and database a bit safe from hackers.

What makes you think that?

Be a part of the DaniWeb community

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