Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Clean URLs with PHP

.htaccess php clean url seo friendly

  • Please log in to reply
38 replies to this topic

#25 RullyHikmatPermana

RullyHikmatPermana

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 19 July 2014 - 11:57 AM

hello sir, 
Thank you for the article. 
 
I got 3 problems Undefined offset: 1 in script
1. $path['query_utf8'] = urldecode($request_path[1]);
2. $path['query'] = utf8_decode(urldecode($request_path[1]));
3. $path['query_vars'][$t[0]] = $t[1];

if I change the number 1 to 0 url get parameter does not work

 

Please help me sir..

thanks

 

 


  • 0

#26 GonzaloMassa

GonzaloMassa

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 08 August 2014 - 01:02 PM

I've just registered on this website to say thank you! This was very helpful!


  • 0

#27 GonzaloMassa

GonzaloMassa

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 08 August 2014 - 01:23 PM

 

hello sir, 
Thank you for the article. 
 
I got 3 problems Undefined offset: 1 in script
1. $path['query_utf8'] = urldecode($request_path[1]);
2. $path['query'] = utf8_decode(urldecode($request_path[1]));
3. $path['query_vars'][$t[0]] = $t[1];

if I change the number 1 to 0 url get parameter does not work

 

Please help me sir..

thanks

 

 

 

I think that part of the code should be inside an if statement:

if(isset($request_path[1])) {
  $path['query_utf8'] = urldecode($request_path[1]);
  $path['query'] = utf8_decode(urldecode($request_path[1]));
  $vars = explode('&', $path['query']);
  foreach ($vars as $var) {
    $t = explode('=', $var);
  $path['query_vars'][$t[0]] = $t[1];
  }
}

If there are no query string variables on the URL, $path['query_vars'] will not exist, you should also check for that when you want to read any of those variables.


  • 0

#28 SamuelLadapo

SamuelLadapo

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 26 October 2014 - 09:07 AM

hello sir am new to php all these you explained i dont get them they are like magic this is a sample of what i want to do like

 

website.php?id=12  to website/articles/this-is-a-test-topic

 

thank you this is the link to my project news.sparkletprojects.zz.vc


  • 0

#29 DamienBradley

DamienBradley

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 26 October 2014 - 02:37 PM

I found this post via DigiCraft's video series, and found a weird problem. I'm working on a localhost for now.

 

When I put a single segment after my base url, e.g "http://localhost:8002/home", $page[call] is blank. This is because of the line of code in the function that compares $path[call] (which is "home") to basename($_SERVER['PHP_SELF']), which is also "home". If I put anything after home, including just a slash, the [call] key is left alone and the [call_parts] array populates. But with just "/home" as my trailing URL, I need [call_parts][0] to be "home", and currently it's blank.

 

Halp?

 

 

Here's all my $_SERVER info:
(
[DOCUMENT_ROOT] => C:\Programming\Projects\AtomCMS
[REMOTE_ADDR] => 127.0.0.1
[REMOTE_PORT] => 52902
[SERVER_SOFTWARE] => PHP 5.5.8 Development Server
[SERVER_PROTOCOL] => HTTP/1.1
[SERVER_NAME] => localhost
[SERVER_PORT] => 8002
[REQUEST_URI] => /home
[REQUEST_METHOD] => GET
[SCRIPT_NAME] => /index.php
[SCRIPT_FILENAME] => C:\Programming\Projects\AtomCMS\index.php
[PATH_INFO] => /home
[PHP_SELF] => /index.php/home
[HTTP_HOST] => localhost:8002
[HTTP_CONNECTION] => keep-alive
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
[HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36
[HTTP_ACCEPT_ENCODING] => gzip,deflate,sdch
[HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.8
[HTTP_COOKIE] => PHPSESSID=havgf73ki6h7ih71a7sa36rnp6
[REQUEST_TIME_FLOAT] => 1414362398.6317
[REQUEST_TIME] => 1414362398
)


  • 0

#30 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 26 October 2014 - 11:34 PM

@Damien, why not just check and if call_parts is not populated, to have it become the value of call?


  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#31 opea

opea

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 25 November 2014 - 02:46 PM

Greetings,

 

Jason, your script works like a charm. It was very easy to follow, however, when I

created a login page that places an ajax call to a file in the same /pages directory,

firebug gives a 404 error message --- file not found. I've tried a few trouble shoots, even tried placing a same page ajax call --- lol. Any help would be greatly appreciated.


  • 0

#32 RobMichiels

RobMichiels

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 21 December 2014 - 07:13 AM

First of all, great post from JasonKnight.

 

I got one problem using this script.

There is always a 1 after the ACTION array and I cant seem to find out where this 1 is coming from.

I use this array for more purposes on my site but after every array this 1 is coming back.

 

Does someone know how I can remove this 1?


  • 0

#33 valient

valient

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 04 March 2015 - 11:27 AM

how can I use this script?


  • 0

#34 ewise

ewise

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 14 July 2015 - 07:56 AM

A problem. If you use file eg about-us.php this not work. Only works all together aboutus.php. One word only. 

 

Anyone know how to fix this?

 

Thank you so much.


  • 0

#35 Upstream

Upstream

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 98 posts
  • Location:Netherlands
  • Programming Language:C, C++, PHP, (Visual) Basic, JavaScript, Perl, Bash, Others
  • Learning:Others

Posted 14 July 2015 - 04:27 PM

Does this come in handy? 

<?php
   // get normal web link 
   $abs_server_path = getcwd();
   $url['scheme'] = (isset($_SERVER['HTTPS']) ? 'https' : 'http');
   $url['domain'] = parse_url($_SERVER['HTTP_HOST'], PHP_URL_PATH);
   $url['path'] = parse_url($_SERVER['PHP_SELF'], PHP_URL_PATH);
   $url['query'] = parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY);
   $link = $url['scheme'] . "://". $url['domain'] . $url['path'] . "/" . $url['query'];
   echo $link . "<br />\n\n";
   echo $abs_server_path . "<br />\n\n";
?>

Results tested:

http://149.20.17.210...se_url.php?s=aa

http://somewhere.omn...se_url.php?s=aa


  • 0
"The question of whether a computer can think is no more interesting than the question of whether a submarine can swim." (Edsger Dijkstra)

#36 FuturedHosting

FuturedHosting

    CC Lurker

  • New Member
  • Pip
  • 9 posts

Posted 27 September 2015 - 07:41 AM

This is a great post! Thanks a lot for this. It is so descriptive that one needs no other related thing to work on this, this one does the magic alone! :)


  • 0





Also tagged with one or more of these keywords: .htaccess, php, clean url, seo friendly