Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

page title in URLs

General discussions related to php

Moderators: macek, egami, gesf

page title in URLs

Postby user786 » Tue Jun 05, 2012 4:17 am

Hi

I installed php and mysql. After i run the website, the URL of pages are like:

c_id=4?m=4

How can i include page title in the URL's ?


Thanks
hammad
user786
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Jun 05, 2012 3:14 am

Re: page title in URLs

Postby ejsexton82 » Tue Jun 05, 2012 10:38 am

So if you have some URL:

http://www.some.url/index.php?c_id=4&m=4&title=Page+Title

You can set the page title with the following code:

Code: Select all
<html>
   <head>
      <title><?php echo $_GET['title']; ?></title>
   </head>
   <body>
      <!-- Body Goes Here -->
   </body>
</html>
User avatar
ejsexton82
New php-forum User
New php-forum User
 
Posts: 86
Joined: Mon Jun 04, 2012 10:05 pm
Location: Ankara, Turkey

Re: page title in URLs

Postby user786 » Tue Jun 05, 2012 10:00 pm

Hi ejsexton82

Thanks for your reply

The code you provided will include page title in the title bar, isnt' it? I wanted that the page title is included in the URL.

Currently URL's are showing like this:

http://www.some.url/index.php?c_id=4&m=4

I want like this:

http://www.some.url/index.php?c_id=4&m= ... f_the_page


Please advise how to do this


Thanks
hammad
user786
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Jun 05, 2012 3:14 am

Re: page title in URLs

Postby ejsexton82 » Wed Jun 06, 2012 11:10 am

I am not sure you can do that without some sort of redirect:

Code: Select all
$pageTitle = urlencode('Title of the Page');
if(empty($_SERVER['QUERY_STRING']) || strpos($_SERVER['QUERY_STRING'],$pageTitle) === false) {
   if(empty($_SERVER['QUERY_STRING'])) {
      $queryString = $pageTitle;
   }
   else {
      $queryString = $_SERVER['QUERY_STRING'] . '&' . $pageTitle;
   }
   header("Location: ?{$queryString}");
   exit;
}


There may also be a way to accomplish the redirect using JavaScript.
User avatar
ejsexton82
New php-forum User
New php-forum User
 
Posts: 86
Joined: Mon Jun 04, 2012 10:05 pm
Location: Ankara, Turkey

Re: page title in URLs

Postby user786 » Thu Jun 07, 2012 1:15 am

Hi ejsexton82

Thank you very much

This code is replacing the complete url with the page title. Due to this page can not be loaded, since the starting URL address like index.php?c_id=4&m=4 is not being included in the URL

I am wondering redirect is the solution to this? Can we not do something that will change the way how php is creating URL's so when each URL is created , it also includes page title in it?

I am also wondering doing this is very important for SEO purpose, there should not be a quick a-b-s like solution available like writing a code line in htaccess, etc ?


Awaiting reply

thanks a lot
hammad
user786
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Jun 05, 2012 3:14 am


Return to PHP General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron